- Home /
How to find the position a specific distance away in a specific direction?
I would like to find the position X meters away to the right of the player. This would not be along the global x axis since the player's right is not always pointing in the direction of the x axis. How can this be done?
Basically you want to return the position xyz based on the given distance from the origin?
Answer by Hamesh81 · May 17, 2015 at 04:01 AM
Ok I have worked it out, the answer is to use Transform.TransformPoint and add the distance: http://docs.unity3d.com/ScriptReference/Transform.TransformPoint.html
Answer by FortisVenaliter · May 16, 2015 at 03:13 PM
transform.right * distance
I tried this but it is moving the player diagonally (right and back) ins$$anonymous$$d of only right (sideways). Here is my code:
transform.position = Vector3.$$anonymous$$oveTowards(transform.position, transform.right distance, Time.deltaTime speed);
For some reason some commas and the * is being removed from my code above, but I think it is clear what I am trying to achieve.
Your answer
Follow this Question
Related Questions
Lerp in direction to certain distance 3 Answers
3d model orientation 1 Answer
How to reach limit line, keep moving, even past over the touch position? 0 Answers
Distance along one axis? 1 Answer
"How far to the local left/right is another object"? 2 Answers