# Collision Response With Moving Object

This topic is 3050 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I am currently trying to add in collision detection / response between my player (represented by a sphere) and a platform (represented by a box). I have got it almost working, as long as my platform does not move in any sort of downwards direction. However when my player is standing on a platform that moves down then my player starts jittering up an down and slides around on the platform slightly! I think it could be to do with the fact that whenever my play lands on any surface he sinks in slightly then gets moved slightly to it's correct position. Here is the code I am using to handle my collisions: // velocity is players velocity // platformV is the platforms velocity if (sphere.Intersects(boxes[boxes.Count - 1])) // If player is on platform velocity += platformV; foreach (BoundingBox box in boxes) // Level collision boxes { if (box.Intersects(sphere)) // Sphere is player sphere { Vector3 closestPoint = box.ClosestPoint(sphere.Center); Vector3 planeNormal = -Vector3.Normalize(sphere.Center - closestPoint); float penetrationDepth = Math.Abs(sphere.Radius - Vector3.Distance(closestPoint, sphere.Center)); float velocityAlongNormal = Vector3.Dot(velocity, planeNormal); float velocityCorrection = (penetrationDepth * 0.25f) + float.Epsilon; if (velocityAlongNormal > -velocityCorrection) { velocity -= planeNormal * (velocityAlongNormal + velocityCorrection); } if (Math.Acos(Vector3.Dot(-planeNormal, Vector3.Up)) < 0.5) isOnGround = true; } } position += velocity; Can anyone see a problem with this code?

##### Share on other sites
Hmm, I have no experience with this, but I think, that you have not to calculate the collision each time the platform moves in the world space.

I mean, that whenever the player hits the platform, it should "connect" the player with it. Then you only have to calculate the collision agains a static platform. It the player is on the ground and the platform is flat, then you have nothing to do :).

Ofcourse, on the end of the calculation, the movement of the platform should be applied to the player. If the player jumpes while the platform moves, then the player should get "disconnected" from the platform. Now you have your initial state: a falling sphere and a moving platform ^^. Whenever some room (train, car, or whatever) moves, calculate the collisions in its own space for the children. You can add acceleration forces of the whole room to the moveable elements.

But calculating the collision of two things, while they both move, is difficult and may end up in solving of some kind of equations to be correct.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 11
• 32
• 12
• 12
• 11
• ### Forum Statistics

• Total Topics
631409
• Total Posts
2999929
×