What exactly is Relative Position? Please help!

Hey!,

I am a beginner at Unity C# scripting I followed the Unity Stealth Project Tutorials for learning scripting. He has used the term relative position ( int context to transform.position and transform.rotation ) I didn’t understand it at all. So what is relative position in 3D vectors and when and why to use it? Please help!

If you can provide examples with explanation that will be great! Also explain in terms of rotation in unity.

Thanks for your time!

It’s relative to the parent gameobject.

https://unity3d.com/learn/tutorials/modules/beginner/editor/the-hierarchy-and-parent-child-relationships

No! I mean that ObjectA.position - ObjectB.position why do u get I dont understand that

You get where ObjectA is in relation to ObjectB.

What do you get when you do 10 - 2?

1 Like

Relative position is the position of an object related to another object. Commonly calculated by otherTransform.position - thisTransform.position. If you are working with a child relative to it’s parent this is equivalent to transform.localPosition.

Think of those action sniper movies where there is a sniper and a spotter. Absolute position would be the spotter giving latitude and longitude. While technically correct, this is difficult for the sniper to use. On the other hand relative position (eg “600 m away at your 3 O’Clock”) is actually pretty useful.

AI is a common use of relative position. Like our sniper, AI wants to know which how far each object is from it’s own position. It makes many calculations much simpler.

There are plenty of other uses for it too.

Edit: And this is vector math. Vector math always starts with a picture. Always. I’m on my phone, so I can’t draw my usual paint masterpiece. This was the best I could find on google.

1 Like

Oh OK so its used to find the distance between u positions? Then why is it used in Lerp when we want certain object to go to the players position why do we do this :-

Vector3 distination = Vector3.Lerp(transform.positon, player.positon - transform.positon, 5f);

transform.position = destination;

I have also seen in the tutorials that it is also used in angles. When we want an object to look at player we find the relative quaternion. Why?

Not distance. Direction.

handy vector math explanations