- Home /
Changing distance with Vector3.Distance
I'm working on making a script in which certain nodes have to be a certain distance apart (doesn't matter how they are apart as long as they are apart by the set distance) and I was hoping we could use something like Vector3.Distance( ) to do this. For example:
distance = Vector3.Distance(transform.position, target.position);
distance = 40;
Well by establishing distance as 40, it would make it 40 (I'm not sure what the measure is) apart. I know this isn't the way it works but what can I do that would serve that purpose?
Answer by Berenger · Apr 09, 2012 at 11:33 PM
First, get the start pos : start = transform.position I guess ?
Second, get the normalized direction : dir = target.position - transform.position
Finally, assemble : target.position = start + dir * 40;
Your answer
Follow this Question
Related Questions
check if an always changing int variable suddenly stop changing 1 Answer
Variables not changing correctly 2 Answers
How to: make changes to a var over real time units instead of frame units? Mathf.Lerp 1 Answer
I want to change the object position random in five particular position only. 0 Answers
Record Object's Position 2 Answers