TX/Tutorials and Guides/TX UserGuide/Physics Responses
From TDN
Contents |
|
[edit] Physics ResponsesThe T2DPhysicsComponent defines 5 stock collision responses that you can use to control the way your object behaves when it collides with something. They are: [edit] BounceThe Bounce collision is a simple collision type which obeys the law "the angle of incidence equals the angle of reflection". It doesn't take into account any other physics parameters like mass or momentum, just the velocity at which the objects are moving when they collide and the angle of impact. The ball in Breakout has a Bounce type collision. [edit] ClampThe Clamp collision is a simple collision type which prevents objects from interpenetrating. When an object with a Clamp collision response runs into another object, its velocity in the direction of the other object is clamped down to zero, while its velocity perpendicular to the other object is unaffected. Characters in platformer games often have Clamp type collisions against walls and floors, which allows the character to slide along them, but not go through them. [edit] RigidThe Rigid collision is a complex collision type which use rigid body physics and Newton's laws of motion to determine what happens to the colliding object. It uses physics parameters like mass, velocity, and angular velocity to determine how the colliding object should move as a result of the collision, as well as the friction properties of the Physics matertials of the colliding objects. A game with hovercraft that can ram into each other might implement a Rigid type collision on the hovercraft. [edit] StickyThe Sticky collision is a simple collision type which sets both the linear and angular velocity of an object to 0 when it collides with something, i.e. it just "sticks" where it is when it hits. The pieces in a stacking game like Tetris might have a Sticky type collision. [edit] KillThe Kill collision response causes the object to be deleted when it collides with something. Projectiles will often be set up with a Kill collision response -- once they hit something you don't want them to hang around in the game, you want to get rid of them. [edit] Custom Physics ResponsesIn addition to the "stock" physics responses, you may also implement your own. In the following example, a custom physics response is created that shrinks the object as it collides:
// protected member delegate
static protected T2DResolveCollisionDelegate _shrinkCollision = new T2DResolveCollisionDelegate(_resolveShrink);
.
.
// our custom resolve method
static protected void _resolveShrink(T2DSceneObject ourObject, T2DSceneObject theirObject,
ref T2DCollisionInfo info, T2DCollisionMaterial physicsMaterial, bool handleBoth)
{
ourObject.Size /= 2;
}
|



