- Home /
,Detect Speed with OnTriggerEnter
I'm working on a game, implementing most of the physics myself (it's a physics project), including the collision. I would like to know how I can read out the speed of an object at the point of the collision using OnTriggerEnter.I understand you get the speed of an object, checking for its velocity.magnitude, but I get completely different values if I use OnCollisionEnter.
private void OnCollisionEnter(Collision collision) { Debug.Log(collision.rigidbody.velocity.magnitude); }
vs.
private void OnTriggerEnter(Collider other) { Debug.Log(other.GetComponent().velocity.magnitude); }
I was wondering why that is and which one actually outputs the correct speed value.
Answer by Vega4Life · Nov 28, 2018 at 08:40 PM
The internal physics update will happen before the collision event is sent. So, whatever collided with it, slowed it down before you were notified through OnCollision.
OnTrigger on the other hand, doesn't have collision, so it should be outputting full velocity.
Your answer
Follow this Question
Related Questions
Colliding two GameObjects 1 Answer
simple onCollision and onTrigger problem 1 Answer
OnCollisionEnter() not getting called between two rigid bodies 3 Answers
OnTriggerEnter do not triggers 1 Answer
Play Audio on Collision or Trigger Enter 4 Answers