- Home /
How to make kinematic body collide using velocity
I need to create a kinematic object where other objects react to it like it has a velocity and angular velocity. A normal Kinematic object ignores its rigidbody's velocity and objects that hit it act like it has zero velocity, so you can't push against an object and have it react as you expect.
I need a way to make a rigidbody that is not be affected by collisions with static and dynamic objects, but still affect the objects it hits, essentially a one-way collision. Collision layers only allow me to prevent collisions both ways.
Currently the Super-Kinematic object is marked as a non-kinematic rigidbody, and am doing some math based on the object's unrestrained motion to set the velocity, which are then used by the physics engine in collisions.
The problem comes as soon as the kinematic object touches the static parts of the scene. The physics engine reacts to the object penetrating the collider by pushing it up with a lot of force, giving it a high velocity that affects any collision with other objects on the same frame.
Here's my current script. The angular velocity piece isn't working yet so I left it out. This works until the object touches a static piece of the scene, at which point, anything it touches on the same frame is likely to go flying away.
public class KinematicPhysics : MonoBehaviour {
Vector3 prevPosition;
// Use this for initialization
void Start () {
prevPosition = transform.position;
}
// Update is called once per frame
void FixedUpdate () {
Vector3 dPosition = transform.position - prevPosition;
rigidbody.velocity = dPosition / Time.fixedDeltaTime;
prevPosition = transform.position;
}
}
Answer by Seth-Bergman · Mar 21, 2013 at 05:38 AM
You can attach a child object to the kinematic one and give that the collision, here's a simple example project, just play the scene if you like..
Thanks, it turned out that rigidbody.$$anonymous$$ovePosition was the piece that I was missing
Your answer
Follow this Question
Related Questions
Projectile collides, freezes, but flips to weird angle. Help! 0 Answers
Realistic collisions with a kinematic rigidbody? 1 Answer
Switch off Kinematic for a Rigidbody in response to an explosion or impact? 1 Answer
Braketorque makes car behave like a kinematic rigidbody 0 Answers
Preventing objects from intersecting with minimal physics 3 Answers