The gameobject “player” is turning around on its own axis even without and input from the mouse or keyboard. Also, it only starts turning after it has moved around the terrain and up some hills, then when i just leave the gameobject and don’t input anything it starts turning. When it spins it is no particular speed in which it spins.
I also found that it spun when it slid down a hill, the larger the gradient the faster the speed of spinning.
here is my movement script;
using UnityEngine;
using System.Collections;
public class PlayerTransport : MonoBehaviour
{
public Rigidbody Rigidb;
public Animator Anim;
int jumpCount = 0;
bool isRunning = false;
bool isJumpCountFull = false;
public float horizontalSpeed = 1.5F;
public float playerH;
public Vector3 pos;
public float movementSpeed;
// Use this for initialization
void Start()
{
Rigidb = GetComponent<Rigidbody>();
Anim = GetComponent<Animator>();
Physics.gravity = new Vector3(0, -119.0F, 0);
}
//public float rotationSpeed = 100.0F;
void Update()
{
rotate();
moveSpeed();
moveAnims();
move();
jump();
}
void rotate()
{
playerH = Input.GetAxis("Mouse X") * horizontalSpeed;
transform.Rotate(0, playerH, 0);
}
void move()
{
float translation = Input.GetAxis("Vertical") * movementSpeed;
//float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
translation *= Time.deltaTime;
//rotation *= Time.deltaTime;
transform.Translate(0, 0, translation);
//transform.Rotate(0,playerH, 0);
}
void moveSpeed()
{
if (Input.GetKey(KeyCode.LeftShift))
{
movementSpeed = 30;
}
else
{
movementSpeed = 12;
isRunning = false;
}
}
void OnCollisionEnter(Collision col)
{
if(col.gameObject.name == "Terrain")
{
jumpCount = 0;
isJumpCountFull = false;
Debug.Log("jumps step 3");
}
}
void jump()
{
if (isJumpCountFull == false)
{
Debug.Log("jumps step 4");
if (Input.GetKeyDown(KeyCode.Space))
{
Rigidb.AddForce(new Vector3(0, 40, 0), ForceMode.Impulse);
jumpCount++;
Debug.Log("jumps step 1");
if (jumpCount == 1)
{
Debug.Log("jumps step 2");
isJumpCountFull = true;
}
}
}
}
void moveAnims()
{
if (Input.GetKey(KeyCode.A))
{
Anim.Play("Walk");
}
else if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.W))
{
isRunning = true;
Anim.Play("Run");
}
else if (Input.GetKey(KeyCode.W) && isRunning != true)
{
Anim.Play("Walk");
}
else if (Input.GetKey(KeyCode.S))
{
Anim.Play("Walk R");
}
else if (Input.GetKey(KeyCode.D))
{
Anim.Play("Walk");
}
else
{
Anim.Play("Idle");
}
}
}