Hi guys, I’m trying to figure out how to calculate the direction between 2 objects. I already got this.
Debug.DrawLine (camera.transform.position, this.transform.position, Color.red, Mathf.Infinity);
With this code i get a DrawLine between object 1 (camera) and object 2 (my object)
But i need the line to go further then just object 2, so I need to know the direction/angle or something.
So my question is:
How to calculate the direction/angle or something between these objects.
Let’s say camera is your point A, and this is your point B.
Vector3 AB = B - A. Destination - Origin.
This is a direction and a distance. To have only the direction (and a distance of 1), you have to normalize it.
AB = AB.normalized OR AB.Normalize()
In your case :
Vector3 pos = camera.transform.position
Vector3 dir = (this.transform.position - camera.transform.position).normalized
Debug.DrawLine (pos, pos + dir * 10, Color.red, Mathf.Infinity);