- Home /
Question by
FlamingWaffels · Feb 08, 2021 at 04:34 PM ·
rotationmovement
How do I rotate my Character Model Toward Movement Direction With my Character Controller?,How Would I Rotate my Character Model toward the Movement Diection?
Hi! I have a model in unity and I would like it to rotate in the direction that it is moving. I have a character controller already setup using a Walking Controller and a Controller. I have it already capable of detecting the direction that the character is moving. Is there a way to rotate it with this?
//NOTE: METHOD ASSUMES ONLY X OR Z VALUE WILL BE NON- ZERO IN DIR PARAMETER, WILL DEFAULT TO Z VALUE
void ChangeFacing(Vector3 dir)
{
if (dir.z != 0)
{
facing = (dir.z > 0) ? FacingDirection.North : FacingDirection.South;
} else if (dir.x != 0)
{
facing = (dir.x > 0) ? FacingDirection.East : FacingDirection.West;
}
//call change facing event
if(OnFacingChange != null)
{
OnFacingChange(facing);
}
if (facing == FacingDirection.South)
{
transform.Rotate()
}
Debug.Log(facing);
}
,I have so far identified which direction that the model is moving and would like to rotate the model in that direction!
void ChangeFacing(Vector3 dir)
{
if (dir.z != 0)
{
facing = (dir.z > 0) ? FacingDirection.North : FacingDirection.South;
} else if (dir.x != 0)
{
facing = (dir.x > 0) ? FacingDirection.East : FacingDirection.West;
}
//call change facing event
if(OnFacingChange != null)
{
OnFacingChange(facing);
}
Is there a way to use this information to tell the model to rotate towards those directions?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613024802im_/https://answers.unity.com/themes/thub/images/avi.jpg)