Gameobject spinning by itself.
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");
}
}
}
Answer by purecrafttube · Jul 13, 2016 at 06:10 PM
Fixed it accedentally:
went onto Rigidbody in the editor and under the constraints section i selected freeze rotation: y
Answer by ReggieBeRetro · Jul 11, 2016 at 01:11 AM
I had somthing like this happen to me when i attached the script that delt with rotation of text to the parent object and not the one i wanted to. Make sure its on the right object if its parented. Just a thought. XD
sorry i meant the transform of the text not rotation.
it is attached to the correct game object but it does have a few child objects but nothing as a parent
Your answer
Follow this Question
Related Questions
How to use the results of a dice roll? 2 Answers
How do i Instantiate sub-Points with in Multiple Points?? 0 Answers
OnGUI will not show up? 1 Answer
My audio doesn't play, I'm through my options... 1 Answer
VS Code or visual studio? 1 Answer