- Home /
Duplicate Question (from http://answers.unity3d.com/questions/485986/face-to-direction-in-a-mario-galaxy-style-game.html)
Move to the direction of movement, in a mechanic similar to Mario Galaxy...
Hello guys, I'm developing a game that uses the mechanics of planets similar to Mario Galaxy.
But I'm having trouble to set a character's face in his direction. I'm trying hundreds of ways, but they all reset values of the X and Z axes, leaving the character in a plan, when in reality it is over a sphere (planet) and its Y axis is always recalculated.
Follow what I'm trying at the moment, for example, direct face-to-left:
private void MovementUpdate () {
var _hor = Input.GetAxis("Horizontal");
var _ver = Input.GetAxis("Vertical");
var _localUp = transform.worldToLocalMatrix.MultiplyVector(transform.up);
var _localRight = transform.worldToLocalMatrix.MultiplyVector(transform.right);
var _localForward = transform.worldToLocalMatrix.MultiplyVector(transform.forward);
//Face to left
if (_hor < 0)
{
var _rotation = Quaternion.LookRotation(-_localRight, _localUp).eulerAngles;
transform.rotation.SetLookRotation(_rotation);
transform.Translate(_localForward * Speed * Time.deltaTime, Space.Self);
}
}
Any help is very welcome, and sorry for my english...
Follow this Question
Related Questions
transform.right = (point on axis) after using LookAt? 2 Answers
[Solved]Make Object face correct direction 2 Answers
[Please!] Noob need's help with planet gravity movement. 2 Answers
Rotate object so a specific axis faces another object, while also relative to the parent direction 1 Answer
Flip 2D object on X axis because of a moving target. 1 Answer