game-physics

Circle to Circle Segment Collision

懵懂的女人 提交于 2019-11-30 07:30:58
I'm struggling to find a rock solid solution to detecting collisions between a circle and a circle segment. Imagine a Field of View cone for a game enemy, with the circles representing objects of interest. The diagram at the bottom is something I drew to try and work out some possible cases, but i'm sure there are more. I understand how to quickly exlude extreme cases, I discard any targets that don't collide with the entire circle, and any cases where the center of the main circle is within the target circle are automatically true (E in the diagram). I'm struggling to find a good way to check

Smooth Keyboard Movement in Pygame

放肆的年华 提交于 2019-11-30 07:30:07
I'm using this code to have a player sprite move around a screen when the arrow keys are pressed: import pygame, sys, time from pygame.locals import * pygame.init() FPS=30 fpsClock=pygame.time.Clock() width=400 height=300 DISPLAYSURF=pygame.display.set_mode((width,height),0,32) pygame.display.set_caption('Animation') background=pygame.image.load('bg.png') UP='up' LEFT='left' RIGHT='right' DOWN='down' sprite=pygame.image.load('down.png') spritex=200 spritey=130 direction=DOWN pygame.mixer.music.load('bgm.mp3') pygame.mixer.music.play(-1, 0.0) while True: DISPLAYSURF.blit(background,(0,0))

Incorrect behaviour with SKPhysicsJointPin when shouldEnableLimits is true and lowerAngleLimit and upperAngleLimit set

心不动则不痛 提交于 2019-11-30 04:26:12
问题 I currently have a ragdoll figure, which consists of a parent node (with no physics bodies attached), and lots of child nodes which each consist of a circle body. The circles are connected to each other using an SKPhysicsJointPin between each circle, as so: Each SKPhysicsJointPin has shouldEnableLimits = true , and I currently use a value of -0.05 and 0.05 for lowerAngleLimit and upperAngleLimit respectively. This works pretty well and prevents the shape from deforming too much, except when

Simulate water/ make sprite “float” on water in spritekit

怎甘沉沦 提交于 2019-11-30 04:05:00
I'm trying to add water to my game. Except for a different background color, there isn't much to it. However, I'd like the player-sprite to float on top of it (or halfway in it). If the player just walks into the water from below, I'd like him to float to the top. If he falls down, I'd like him to slowly change direction and float back up. I tried making the gravity negative when he's in the water, but this gives me some slightly unwanted effects. For example as he (the player) surfaces, the normal gravity will push him back down, the water will push him up, and so on. Ultimately the player

How to create a rope in SpriteKit?

给你一囗甜甜゛ 提交于 2019-11-30 03:59:52
I want to create a rope like the one that is shown in this video . What is the best way to develop a rope like this? I've already tried to start and I think the best way to do it, is to make many little "rope"-parts and connect them with a pin joint (is that really the best one?!?). But I didn't know how to start. Maybe someone can give me some example code for that.. THX :) I am the author of that video. Because of the big demand for the source code I have released it on the Github. You can find it here zinne I've also done a rope with single parts connected with PinJoints. I think it's the

KDTree Splitting

為{幸葍}努か 提交于 2019-11-30 00:32:40
I am currently writing a KDTree for a physics engine (Hobby project). The KDTree does not contain points. Instead it contains Axis Aligned bounding boxes which bound the different objects in the environment. My problem is deciding on how to split the KDTree nodes when they get full. I am trying 2 methods: Method1: Always split the node exactly in half on the biggest axis. This has the advantage of a pretty evenly spaced out tree. Big disadvantage: If objects are concentrated in small area of the node, redundant sub-divisions will be created. This is because all volumes are split exactly in

Cocos2dx - Unable to set velocity = 0.0

无人久伴 提交于 2019-11-29 16:22:26
I'm making an pool game with cocos2dx. First, i setup the edgeBox with this parameters PhysicsMaterial(1.0f, 1.0f, 0.8f) And then these 2 balls PhysicsMaterial(1.0f, 1.0f, 0.5f) On the update function, i want slow down balls time by time without gravity (like making ground friction) by adding physicsBody->setLinearDamping(0.3); On the update function, i set the minimum velocity, if the velocity of each ball reaches lower than 15, reset velocity to 0,0 auto MV = 15; auto v1 = player1->getPhysicsBody()->getVelocity(); auto v2 = player2->getPhysicsBody()->getVelocity(); if (v1.x > MV || v1.x <

Movement Without Framerate Limit C++ SFML

心不动则不痛 提交于 2019-11-29 15:08:15
问题 I'm working an making a game in SFML right now, but I am getting stuck on movement without a framerate limit. Right now the only way I have figured out how to get consistent framerate on all computers is by using window.setFramerateLimit(30); I want to find a way to not have a framerate cap so it does look better on better computers and so that if anybody has a really slow computer, they can still play the game. What would be the best way to do this. 回答1: You should pass the time that has

SpriteKit SKPhysicsBody bodyWithTexture is Upside Down

不想你离开。 提交于 2019-11-29 04:30:32
Hi I'm trying to fix this bug with spritekit's physics shape appearing upside down. [SKPhysicsBody bodyWithTexture:monsterTexture size:monsterTexture.size] The first time the monster appears the phsyics body orientation is correct. But the second time and every time after that the monster appears it's physics body is inverted along the Y axis. See picture where skView.showsPhysics = true; so the physics shapes are displayed. The fact that it works correctly the first time makes me think maybe some property I'm not aware of is being modified or something. I thought of putting 2 physics blocks

How to create a rope in SpriteKit?

天涯浪子 提交于 2019-11-29 01:10:43
问题 I want to create a rope like the one that is shown in this video. What is the best way to develop a rope like this? I've already tried to start and I think the best way to do it, is to make many little "rope"-parts and connect them with a pin joint (is that really the best one?!?). But I didn't know how to start. Maybe someone can give me some example code for that.. THX :) 回答1: I am the author of that video. Because of the big demand for the source code I have released it on the Github. You