I’m working on a 2d top-down game and I am having some issues with collision response. In the game I plan on using line segments to define walls that entities collide with. The entities collision shapes are circles (position and radius). I have a working demo set up that lets me collide a sphere into a line segment and stop the entities movement by setting its current position to its previous position when a collision is detected.
Now the issue is when an entity is against a wall it will begin to rapidly tremble depending on how fast it can accelerate. I cant seem to figure out how to make it smooth. Also, when I try to move the entity along the wall it will bounce and lag. Anyone have any ideas?
Here is the Entity class Update method :
public void Update(GameTime gameTime, List<LineSegment> walls)
{
float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
if (!InputManager.IsThumbstickIdle(TriggerType.Left))
{
direction = InputManager.ThumbstickVector(TriggerType.Left);
angle = InputManager.ThumbstickAngle(TriggerType.Left);
velocity = (direction * _speed);
for (int i = 0; i < walls.Count; i++)
{
LineSegment line = walls[i];
if (CollisionSolver.CirlceIntersectsLine(circle, line))
{
position = previousPosition + (line.Normal * Vector2.One);
circle.Position = position;
}
}
}
else
{
velocity = Vector2.Multiply(velocity, _damping);
}
previousPosition = position;
position += velocity * elapsedTime;
circle.Position = position;
}
If more of the code is needed just let me know and I will post it. Thanks in advance for any help!

New Topic/Question
Reply


MultiQuote




|