- Home /
Character rotation without affecting control orientation
So my game has the player character walking around along the x and z axis with a static camera. There is no jumping involved.
What I have so far (Unity Script) which moves the character in the direction the controls are pushed, and it works just fine.
function Update ()
{
//movement
var contr : CharacterController = GetComponent(CharacterController);
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= moveSp;
contr.Move(moveDirection * Time.deltaTime);
What I don't have working is if I push a control, I want the character to face that direction as well as move that way. I have tried a lot of things, and they all end up rotating the character instead of walking in that direction. And then of course if I push up the character walks in that direction instead of going up. I have a feeling that transform.Rotate isn't the direction I should be taking.
I plan on adding some sort of rotation smoothing as well, however pointing me in the right direction would be a big help. Please forgive me for being a newb, I haven't done any programming since I was a kid with a c64.
Answer by armoredpokey · Apr 24, 2013 at 02:30 AM
Try flipping the sign of transform.localScale. E.g. something like:
absoluteValue = Mathf.Abs(transform.localScale.x);
sign = Input.GetAxisRaw("Horizontal");
if (sign == 1 || sign == -1)
transform.localScale.x = absoluteValue * sign;
Your answer
Follow this Question
Related Questions
EARTH CALLING ANSWER!!!! 1 Answer
Get the needed rotation to face other object 1 Answer
making my space ship rotate then move. 0 Answers
Movement based on camera 1 Answer