- Home /
Match local axis with direction
So here I have a surface , an icosphere , with a player , the cube , and the destination , the red line pointing upwards over the other side. To reach the destination I am pushing the player forward , however to reach the destination I would have to rotate the LOCAL y of the player to face the red line.
This is the result I would need to achieve for the player to reach the destination by moving forward. However since my vector maths is quite terrible , I don't know where to go from here , how would I calculate the angle and rotate the player only on it's local y axis?
Answer by fleischverpackung · Aug 30, 2017 at 02:12 PM
Maybe this thread helps? Running around small planets.
Answer by NorthStar79 · Aug 30, 2017 at 02:28 PM
only two solutions come to my mind so far. first one : make your cube child of an emptyGameObject, move that empty gameobject as usual movement, also add rigidbody to empty game object, and write something like this.
CubeObject.transform.rotation = Quaternion.Lerp(CubeObject.transform.rotation,Quaternion.LookRotation(-emptyGameObjsRigidbody.velocity),5);
or maybe:
CubeObject.transform.LookAt(ParentEmptyGameObj.transform.TransformVector(Vector3.forward));
its hard to suggest a solution with no information about your project, scripts etc.
second one :
project two lines (red and blue ones) onto a plane. and find theirs intercept point (its simple vector math, not that hard you can do it) and rotate your cube towards that intercept point.
normaly , i would go for second one..
Your answer
Follow this Question
Related Questions
Can't change vector direction 0 Answers
Find intersecting points between vectors 1 Answer
Unity ML-Agents Game,Unity ML-Agents Space Shooter Game 0 Answers
Vector3.Angle getting twitchy with small angles 0 Answers
Is it possible to clamp a Vector magnitude upwards (i.e. clamp to minLength)? 2 Answers