[resolved] Calculate collision angle

Hey dear community,

I want to calculate the angle of a collision.

36563-collions.png

What do I know?

  • the point where both Object 1 and Object 2 collide
  • transform.position of Object 1 and Object 2

What do I need to know?

  • the direction vector of Object 1

How do I want to do that?

1 - Find out the collision point

colPoint = Collision.contacts[0].point;

2 - Find out the position of Object 1 and the collision Point to get the vector from Object1 to collisiont point

heading = colPoint - object1.transform.position;

3 - find the orthogonal vector of “heading” with

tangent = Vector3.OrthoNormalize(heading, colPoint);

4 - and here it stops… I would like to know the movement vector to calculate the angle of tangent and movement vector

I know how to calculate the angle.

My idea is… but it doesnt work to make a “for - loop” that checks ever update or fixed update the positions between the updates. to calculate the movement vector. but that seems to be too intensive if I do that with several thousand objects at the same time.

is there a function in unity to get this vector? I didnt found yet. The only things I found where how to face an object in direction of movement. But the code and ideas they where introduced there doesnt help me.

Maybe I have an error in the way I think. Any idea?

I really would appreciate your help!

I don’t want to get a working code. Just an idea! :slight_smile:

best wishes,
Christian

edit: SOLUTION:

var orthogonalVector = col.contacts[0].point - transform.position;
var collisionAngle = Vector3.Angle(orthogonalVector, rigidbody.velocity);

Can you not take Object 1’s normalized velocity (I assume you are using rigid-bodies since you are using contact points)?

If so, a coroutine that waits until the end of frame, then returns the normalized velocity after collision may give you what you want.