Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get new location from Quaternion and Vector3 in Unity

I have a Vector3 and a Quaternion, what is the best way to get the coordinates of a location a certain distance in front (or behind).

What I am trying to do is this:

Gizmos.color = Color.red;
var direction = transform.TransformDirection(Vector3.forward) * 1000;
Gizmos.DrawRay(transform.position, direction);

Just without access to the transform, but with the (Quaternion) rotation and and coordinates (Vector3)

like image 730
SondreBBakken Avatar asked Oct 12 '25 02:10

SondreBBakken


1 Answers

If you multiply a world rotation with Vector3.forward you will get the same as using the respective transform.forward

public Vector3 GetPosition(Quaternion rotation, Vector3 position, float distance)
{
    Vector3 direction = rotation * Vector3.forward;
    return position + (direction  * distance);
}

You could use Ray but that would be overkill

like image 53
Riaan Walters Avatar answered Oct 14 '25 17:10

Riaan Walters