Question by
ASE_Blast · Jul 15, 2020 at 08:42 PM ·
c#charactercontrollerthird person controller
I want to make it so that my character wont turn right when i press the right key, or left when i press the left key. Can anyone help plz?
void Update()
{
float horizontal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
if(direction.magnitude >= 0.1f)
{
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnToSmoothTime);
transform.rotation = Quaternion.Euler(0, angle, 0);
Vector3 moveDirection = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
controller.Move(moveDirection.normalized * speed * Time.deltaTime);
}
Comment
Your answer
Follow this Question
Related Questions
MoveTowards is curving for no reason 0 Answers
How to crouch a FPS Controller? 2 Answers
Character's jumping mechanism stuck into something invisible 1 Answer
Jump over obstacles(runner game) by speech recognition 1 Answer
Help with 2D platformer (score),For my 2D game sometimes coins get added twice to the score?! 0 Answers