Look rotation viewing vector is zero & diagonal boosting
I've been having a couple of problems that I'm sure has a simple answer to. Firstly, I can't quite solve why my character is running so quickly when travelling diagonally. I've tried normalizing and clamp.magnitude but then that just messes up the jumping.
Secondly, I've been getting the "Look rotation viewing vector is zero" warning and it's been having actual effects on the game. The error would only show up when jumping without moving joysticks and would rotate the character to face forward. It would even happen in midair if I let go of the joystick while falling.
Any help would be greatly appreciated, thanks in advance.
void Update()
{
var horizontalAxis = Input.GetAxis("Horizontal");
var verticalAxis = Input.GetAxis("Vertical");
transform.Translate(moveRotation * speed * Time.deltaTime, Space.World);
if (knockBackCounter <= 0 && healthMan.knockedOut == false)
{
//Enables you to move the player
moveDirection = new Vector3(horizontalAxis * speed, moveDirection.y, verticalAxis * speed);
moveRotation = new Vector3(horizontalAxis, 0, verticalAxis);
//Jumps only when touching the ground
if (cc.isGrounded) {
moveDirection.y = 0f;
if (Input.GetButtonDown("Jump"))
{
moveDirection.y = jumpForce;
}
}
} else
{
knockBackCounter -= Time.deltaTime;
}
//Does light Attack
if (Input.GetButtonDown("Attack"))
{
anim.Play("attack_Light");
sound.PlayOneShot(attackSound, 0.5f);
} else
{
anim.Play("No Attack");
}
//Sets your player from playable to knocked out
if (healthMan.knockedOut == true)
{
moveDirection = new Vector3(0, 0, 0);
}
//Player faces direction of movement
if (moveDirection != Vector3.zero)
{
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(moveRotation), Time.deltaTime * rotationSpeed);
}
moveDirection.y = moveDirection.y + (Physics.gravity.y * gravityForce * Time.deltaTime);
cc.Move(moveDirection * Time.deltaTime);
}
Your answer
Follow this Question
Related Questions
My jump scripit wont work. i have been tryingtt o make it work for an eternity. please help. 1 Answer
Photon Player Mover Failure 1 Answer
Issues Getting my GameObject to both Move Forward and Jump properly. 0 Answers
How can I make it so that the longer you hold down the jump button the higher the player jumps? 0 Answers
Unexpected symbol '=' parser error and Unexpected symbol '(' error 1 Answer