- Home /
Its spazzing out when trying to flip 3D model
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed;
public float jumpForce;
public CharacterController controller;
private Vector3 moveDirec;
public float gravityScale;
void Start()
{
controller.GetComponent<CharacterController>();
}
void Update()
{
moveDirec = new Vector3(Input.GetAxis("Horizontal") * speed, moveDirec.y);
if (controller.isGrounded && Input.GetButtonDown("Jump"))
{
moveDirec.y = jumpForce;
}
moveDirec.y = moveDirec.y + (Physics.gravity.y * gravityScale);
controller.Move(moveDirec * Time.deltaTime);
if (Input.GetAxis("Horizontal") < -0.001f)
{
transform.Rotate(0f, 180f, 0f);
}
if (Input.GetAxis("Horizontal") < 0.001f)
{
transform.Rotate(0f, -180f, 0f);
}
}
}
It's spazzing out and I don't know why... Clip: https://gfycat.com/PointedLikelyCockroach
Comment
Best Answer
Answer by xxmariofer · Mar 18, 2019 at 07:52 PM
change the last 2 ifs to this
if (Input.GetAxis("Horizontal") < -0.001f)
{
transform.rotation = Quaternion.Euler(0f, 0, 0f);
}
if (0.001f < Input.GetAxis("Horizontal"))
{
transform.rotation = Quaternion.Euler(0f, -180f, 0f);
}
Your answer
Follow this Question
Related Questions
How do i Achieve mesh Extrusion? 2 Answers
Szise is wrong in build 2 Answers
[Unity 3D] How to detect if the game object is left right from the player? 0 Answers
When I look around, my character rotates in a weird circle and it causes it to move around. 0 Answers
How do i cast mesh like a linerenderer? 0 Answers