Weird Character getting stuck glitch
Posted: Sat Aug 20, 2011 1:50 pm
Hey Norbo, hope you're well.
I've been using this excellent physics engine of yours for a few weeks now, ever since I stripped out all of my shoddy collision detection code and rebuilt using BEPU. My game is a little bit of an unusual choice for BEPU. It's a 2D game with a perspective similar to legend of zelda: link to the past.
Right now, I'm using pretty simple features of BEPU: all walls are kinematic boxes. All characters and objects are simply dynamic boxes that slide around with their LocalInertialTensorInverse zeroed out. I'm also using spheres for things like detecting when a sword swing has hit someone, or when a player is in range of an object they can interact with. In order for these detection spheres to not collide with the solid objects in the simulation, I've made use of Collision Groups. Spheres which are meant to detect players are part of a collision group that has the rule NoBroadPhase with every other group except for Players, with whom they share a No Solver rule. I then hook up the events InitialCollisionDetected and CollisionEnded on the detection sphere in order to do stuff when a player has moved into or out of the sphere area.
The problem is, I think my player's box is actually colliding with the detection sphere, even though their collision groups are set to use NoSolver with each other. Basically, what happens is that one out of every hundred or so times I move into a detection sphere (it seems to be random), the player's character simply stops moving. The odd thing is that, while stuck, the character's box reports that its linear velocity is quite high -- the linear velocity actually freezes in place at whatever it was at when the collision between the character's box and the detection sphere took place. So the character's velocity is reported as moving at full speed, but instead the character is stuck in place, right at the edge of the sphere. Any collision with some other object in the simulation will free it. Simply moving as the player will not free the character, because right now my character movement just applies a linear velocity to the character only if its moving below a certain speed threshold. So, when the linear velocity is reported as being high, the movement controls don't do anything.
A few more points that might be significant:
I recently switched my XNA game object to IsFixedTimeStep = false. It fixes a pretty annoying screen jitter for me. Not sure, but the issue might not exist when IsFixedTimeStep = true.
I've tried passing the (float)gameTime.ElapsedGameTime.TotalSeconds into space.Update(), and I still get the problem.
Also, the detection sphere is itself connected to a solid box object by means of a BallSocketJoint. The solid box is part of a different collision group which is set on NoBroadPhase with the detection sphere. Not sure if this could cause problems.
I've tried enabling Buffered States and only adding and removing things by way of the SpaceObjectBuffer. Doesn't seem to make a difference. Tomorrow I'll try messing around with continuous collision detection and the three Position Update Modes. If that stuff doesn't work, I may just try to redo character collision with the simpleCharacterController you built, and see if that has the same issue.
If any common mistakes or problems come to mind with what I'm describing, I'd love to hear. This is the hardest to track down bug I've run into yet.
Thanks for the amazing engine -- couldn't have built anything this cool in years of work, and using it I've been able to get an action RPG practically up and running in two months. (This is actually my first real game project).
Let me know if posting a video would help. I could try recording something with fraps.
Alex
I've been using this excellent physics engine of yours for a few weeks now, ever since I stripped out all of my shoddy collision detection code and rebuilt using BEPU. My game is a little bit of an unusual choice for BEPU. It's a 2D game with a perspective similar to legend of zelda: link to the past.
Right now, I'm using pretty simple features of BEPU: all walls are kinematic boxes. All characters and objects are simply dynamic boxes that slide around with their LocalInertialTensorInverse zeroed out. I'm also using spheres for things like detecting when a sword swing has hit someone, or when a player is in range of an object they can interact with. In order for these detection spheres to not collide with the solid objects in the simulation, I've made use of Collision Groups. Spheres which are meant to detect players are part of a collision group that has the rule NoBroadPhase with every other group except for Players, with whom they share a No Solver rule. I then hook up the events InitialCollisionDetected and CollisionEnded on the detection sphere in order to do stuff when a player has moved into or out of the sphere area.
The problem is, I think my player's box is actually colliding with the detection sphere, even though their collision groups are set to use NoSolver with each other. Basically, what happens is that one out of every hundred or so times I move into a detection sphere (it seems to be random), the player's character simply stops moving. The odd thing is that, while stuck, the character's box reports that its linear velocity is quite high -- the linear velocity actually freezes in place at whatever it was at when the collision between the character's box and the detection sphere took place. So the character's velocity is reported as moving at full speed, but instead the character is stuck in place, right at the edge of the sphere. Any collision with some other object in the simulation will free it. Simply moving as the player will not free the character, because right now my character movement just applies a linear velocity to the character only if its moving below a certain speed threshold. So, when the linear velocity is reported as being high, the movement controls don't do anything.
A few more points that might be significant:
I recently switched my XNA game object to IsFixedTimeStep = false. It fixes a pretty annoying screen jitter for me. Not sure, but the issue might not exist when IsFixedTimeStep = true.
I've tried passing the (float)gameTime.ElapsedGameTime.TotalSeconds into space.Update(), and I still get the problem.
Also, the detection sphere is itself connected to a solid box object by means of a BallSocketJoint. The solid box is part of a different collision group which is set on NoBroadPhase with the detection sphere. Not sure if this could cause problems.
I've tried enabling Buffered States and only adding and removing things by way of the SpaceObjectBuffer. Doesn't seem to make a difference. Tomorrow I'll try messing around with continuous collision detection and the three Position Update Modes. If that stuff doesn't work, I may just try to redo character collision with the simpleCharacterController you built, and see if that has the same issue.
If any common mistakes or problems come to mind with what I'm describing, I'd love to hear. This is the hardest to track down bug I've run into yet.
Thanks for the amazing engine -- couldn't have built anything this cool in years of work, and using it I've been able to get an action RPG practically up and running in two months. (This is actually my first real game project).
Let me know if posting a video would help. I could try recording something with fraps.
Alex