lets say I have the following function with my character
if (game.currentState.IsKeyDown(Keys.Left))
{
body.Position -= distance;
}
However, my character/box collision will pass thru the kinematic blocks with continuous key press of LEFT arrow.
Is there anything i can do to stop the character from passing thru the blocks?
body.PositionUpdateMode = PositionUpdateMode.Continuous;
i have tried the positionupdatemode but it did not help
Problem with Collision
Re: Problem with Collision
Setting the position (or orientation) of an entity discontinuously teleports it. Since there is no velocity involved, the collision response solver can't do much. It will 'squish' the objects apart over time due to position correction, but the usual rigid collision response will be absent.
If you want rigid response, then you should control the motion using velocity, or equivalently with impulses.
If you want a character in particular, check out the SimpleCharacterController(Input) and CharacterController(Input) in the BEPUphysicsDemos.
If you want rigid response, then you should control the motion using velocity, or equivalently with impulses.
If you want a character in particular, check out the SimpleCharacterController(Input) and CharacterController(Input) in the BEPUphysicsDemos.
Re: Problem with Collision
Thanks it really helps a lot.
However if i am using body.LinearVelocity, i should set a maxSpeed to it in order to limit the acceleration? Also i noticed that i will slightly penetrate through the collision box when i jump from a lower platform to a higher one. Is there anyway to solve this?
lets say i have this map.txt file to load in the map
1 = platform
0 = empty space
x = character
000X000001111111111
1111111111111111111
However if i am using body.LinearVelocity, i should set a maxSpeed to it in order to limit the acceleration? Also i noticed that i will slightly penetrate through the collision box when i jump from a lower platform to a higher one. Is there anyway to solve this?
lets say i have this map.txt file to load in the map
1 = platform
0 = empty space
x = character
000X000001111111111
1111111111111111111
Re: Problem with Collision
The (Simple)CharacterController shows how to do this. However, you may want to just use the (Simple)CharacterController directly. It handles a lot of stuff for you.However if i am using body.LinearVelocity, i should set a maxSpeed to it in order to limit the acceleration?
The basic idea is that you compute the magnitude of the velocity and compare it with the maximum speed. Clamp the velocity change such that the character cannot accelerate itself beyond its maximum speed. Note that this is different from normalizing the whole velocity together AFTER changing the velocity; such an approach would inappropriately prevent the object from accelerating beyond the maximum speed if it got smashed by external forces.
Slight penetration is expected. All collisions are allowed to penetrate up to specified CollisionDetectionSettings.AllowedPenetration. No penetration correction forces are applied when penetration is below this threshold. This prevents jittering from contacts coming into and going out of existence rapidly.Also i noticed that i will slightly penetrate through the collision box when i jump from a lower platform to a higher one. Is there anyway to solve this?
If you're seeing significant overlap due to allowed penetration, that would imply you are working on very tiny scales. AllowedPenetration defaults to 0.01. If your objects' are very tiny, smaller than 0.2 units, this may become problematic (along with other tuning variables). The engine is tuned for objects with dimensions of 0.5 to 10 units. Going above this limit is usually fine, but sticking within the range helps guarantee stability. Technically, it's possible to retune the engine to work with different scales so long as sufficient floating point precision is available, but this is usually far more work than just ensuring everything is the appropriate scale.
Another possible issue is that the velocity is high enough that discrete collision detection only sees the collision once the objects are already interpenetrating a ways. The first frame of collision may have up to Space.TimeStepSettings.TimeStepDuration * velocity penetration when using discrete collision detection. Any penetration caused by this should be small if the velocities involved are small and should correct very quickly. Using continuous collision detection will limit the amount of penetration and will prevent the collision from being missed entirely.