Tricks for collisions and fast moving objects?
by Matthew Hoesterey · in Torque X 2D · 03/16/2009 (9:08 pm) · 1 replies
Hi, I'm having some trouble with a fast moving object that moves through a floor before it detects the collision. My floors need to be really thin (only a few pixels)
I have some ways to cheat (ie draw a rec return all objects in the rectangle find the closest).
I was hoping that a solution already existed in the engine (solve overlap doesn't work as the objects too fast)
I found a TestMove method I was going to experiment with. Does anyone have experience with this method?
Anyone know a solid way to check for these fast moving collisions?
Thanks :)
I have some ways to cheat (ie draw a rec return all objects in the rectangle find the closest).
I was hoping that a solution already existed in the engine (solve overlap doesn't work as the objects too fast)
I found a TestMove method I was going to experiment with. Does anyone have experience with this method?
Anyone know a solid way to check for these fast moving collisions?
Thanks :)
Torque Owner Matthew Hoesterey
/* This Method is used to stop fast moving players from going through the ground * Searches for a collision along a vector. */ public Vector2 CheckFastCollision(T2DSceneObject mover, Vector2 offset) { List<T2DCollisionInfo> collisions = new List<T2DCollisionInfo>(); T2DSceneObject _collider = TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>("ColliderMovement"); CharacterDataComponent moverCharData = mover.Components.FindComponent<CharacterDataComponent>(); float x = mover.Position.X; float y = mover.Position.Y; _collider.Position = new Vector2(x, y); if(moverCharData != null) _collider.Size = new Vector2(moverCharData.PhysWidth, _collider.Size.Y); Vector2 landPoint = new Vector2(x + offset.X, y + offset.Y); Vector2 target = landPoint; _collider.Collision.TestMoveTo(ref target, collisions); foreach (T2DCollisionInfo tci in collisions) { if (tci.Position.Y < landPoint.Y && tci.Position.Y > mover.Position.Y) { landPoint = new Vector2(x, tci.Position.Y); if (mover.Position.Y + (mover.Physics.VelocityY/10) > landPoint.Y) { mover.Position = new Vector2(mover.Position.X, landPoint.Y - moverCharData.FootOffset); mover.Physics.Velocity = new Vector2(mover.Physics.VelocityX, 0); } } } return landPoint; }