- Camera look direction
- Use to calculate relative rotation to transform.rotation
- Move direction
- Use to calculate relative rotation to transform.forward
- Set foot IK goals and weights
- Get goal positions
- Add/subtract in forward direction based on speed
- Use look direction to get look position
lookDirection = mainCam.transform.forward
lookDirection.y = 0f
- Clamp to XZ plane
lookPosition = transform.position + lookDirection
- SetLookAtPosition with look position
- Rotates upper body
controller.Move(transform.position + transform.forward * speed * moveRate);
-
moveRotation = Quaternion.AngleAxis(Vector3.SignedAngle(transform.forward, moveDirection, transform.up), transform.up)
-
Get difference between move direction and look direction
difference = Vector3.SignedAngle(moveDirection, lookDirection, transform.up)
- If difference > or < than max/-max
- Add difference to move rotation
moveRotation *= Quaternion.AngleAxis(difference - max or + max, transform.up)
- Set animator float for rotation
- Triggers turn in place animation if idle
- Triggers lean if moving
- Add difference to move rotation
-
Rotate transform to move rotation
transform.rotation *= moveRotation
- Will be 0 rotation when look direction is inside max range and transform forward = move direction