Getting the peripheral?

Hello,
I was wondering if there is a way to code a function to where it takes in two different objects, and if ‘object 2’ is directly in front of whatever direction ‘object 1’ is facing (in 3D space), it returns a 1, if it is directly to the right or left or up or down, it returns a 0, and if it is directly behind, it returns a -1.

Thank you,
Michael S. Lowe

hi,
you can use vector Dot product of two object

Yes it would be the dot product. More specifically, it would be a dot product of Object1’s forward axis, and the vector between the two objects.

Vector3.Dot(object1.forward, (object2.position - object1.position).normalized);

There’s an example of this in the documentation.

Thank you.

1 Like