- Home /
Controllable ball rolling away by itself
I'm new to unity and following this tutorial on making a basic ball game. whenever I start the game, the ball automatically rolls to the left as if I'm holding the 'A' key. I can make roll back to the right by holding 'D', but as soon as I let go of 'D' it rolls back the left again.
this is the code I'm using to control the ball:
#pragma strict
var rotationSpeed = 100;
function Update ()
{
var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
rotation *= Time.deltaTime;
rigidbody.AddRelativeTorque (Vector3.back * rotation);
}
Thanks in advance. :)
start by adding this line to your Update:
Debug.Log(Input.GetAxis ("Horizontal"));
then hit play, and see if the Debug log shows as 0 (while not pushing any buttons). Or does it ins$$anonymous$$d show a positive number?
Thanks for the reply, the debug shows a value of -1, and when I hold D its changes to a value of 1, let go of D, it goes back to -1. Any ideas on what might be causing this and how to fix it? Thanks.
hmm.. open your input manager:
http://docs.unity3d.com/Documentation/Components/class-Input$$anonymous$$anager.html
try changing the name of the SECOND "Horizontal" to something else.. (the one that says joystick) then test again (just a longshot)
Thankyou!! worked just fine when I renamed it to Hoizontal2. I have a flight stick and a controller connected to my PC, it must have been getting the value from one of them? Once again, thanks for helping me out! :)
yep, that's exactly what it was. Glad to help!
I'm going to post the solution as an answer, please accept it so others will know..
Answer by Seth-Bergman · Dec 14, 2013 at 08:52 AM
(copied from comments)
hmm.. open your input manager:
http://docs.unity3d.com/Documentation/Components/class-InputManager.html
try changing the name of the SECOND "Horizontal" to something else.. (the one that says joystick) then test again (just a longshot)
Answer by TP3 · Dec 10, 2015 at 05:11 PM
I'm a beginner, but I also had a ball that was moving by itself, even if the player controller script was disabled/deleted. There's probably several things that could've gone wrong for you or I but for me the issue was the 'Walls'.
I assume as they are quick and rough cubes that are all overlapping/touching the 'Ground' was getting somehow shook very slightly in weird ways which could not be seen by the eye. By lifting the 'Walls' in the hierarchy so they were not touching the 'Ground' the issue went away. I'm sure in a real game walls wouldn't be created from 4 duplicated cubes and would be perfectly positioned, so not too big of an issue but i'm glad I found the culprit eventually.
Your answer
Follow this Question
Related Questions
How to roll the ball? 1 Answer
How to make a ball that can roll? 2 Answers
Rolling ball Text error. Removes itself when played 0 Answers
Making a ball roll and keeping the axis? 2 Answers
Problem with joystick movement 1 Answer