Set vehicle driver position (calculate position with angle and distance)
Hello, I am trying to set the drivers position (3D) relative to the vehicle rotation. E.g. the driver seat is 45° to the front left from the cars origin with a distance of 2.
My first approach was to use Cos, Sin and Tan but this didn't end up in the desired result. To be honest I am a bit confused by the 3D dimension.
Vector3 pos = vehicle.transform.position;
Quaternion dir = vehicle.transform.rotation;
driver.transform.position = new Vector3(pos.x + Mathf.Cos((45+dir.x)*Mathf.Deg2Rad)*2, pos.y + Mathf.Sin(dir.y*Mathf.Deg2Rad), pos.z + Mathf.Tan((45+dir.z)*Mathf.Deg2Rad)*2);
Comment
Answer by leschge · Feb 19 at 02:08 PM
A bit more research led me to this working solution:
Vector3 pos = vehicle.transform.position;
Quaternion dir = vehicle.transform.rotation;
Vector3 relDir = new Vector3(-1, 0, +1);
driver.transform.position = pos + dir * relDir * 2f;
//Additional rotation transform to make the player "fixed" in the seat
driver.transform.rotation = vehicle.transform.rotation;
Your answer
Follow this Question
Related Questions
How to convert User Values into degree(Angle)?? 2 Answers
Align a object's rotation to another object 0 Answers
Is it possible to restrict the viewing angle for a while in GOOGLEVR? 0 Answers
Struggling to get the rotation the player is moving in. 1 Answer
Rotation and Turn Giving Odd Angle 0 Answers