- Home /
Roll-A-Ball Tutorial: Ball moves on its own
Hi,
I have completed the Roll-A-Ball tutorial successfully.
There's only one issue I'm having: When running the game, even if I don't do anything, after about 10 seconds the ball starts rolling forward slowly on its own.
This is highly undesirable. Because there is some force acting on the ball that I did not intend. It does not affect this simple game too much, but it could be a bigger issue in bigger projects.
I'm using Unity 5, and the tutorial was made in a 4.x version I think. So, maybe this has something to do with it.
Can anyone tell me what is causing this?
The zip file for my project can be found here: http://forum.unity3d.com/threads/roll-a-ball-tutorial-ball-moves-on-its-own.312714/ in the forums where I originally asked this question.
Im on mobile for now so cannot check the zip file atm BUT the very simple solution is adding a drag value to the ball while no input is detected.
If you are on an incline, as in your whole plane is inclined this will happen, check that the surface is right angle(perpendicular) to the force of gravity?
Im having the same issue. It feels like Unity isnt recognizing that im pressing the arrow keys to move the ball. I press my arrow keys and nothing happens. Then after a few seconds it starts rolling on its own, slowly in one direction.
I have this exact same problem when I press left or right or the alt key a or d nothing happend then after a few seconds the ball slowly starts rolling in one direction on its own. my code is a little different than yours though:
using UnityEngine; using System.Collections;
public class PlayerController : $$anonymous$$onoBehaviour { public float speed;
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVetical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVetical);
GetComponent<Rigidbody>().AddForce (movement * speed * Time.deltaTime);
}
}
@ozturkcompany, that may fix it, but it would be a hack. I want to identify the root cause of the problem.
Answer by turacept · Apr 03, 2015 at 08:02 PM
The rigidbody is probably doing something funky. are you sure the controller has all of the axis's written in correctly? I used to have that problem alot. I would make a controller and then I would forget the names of my axis's so I did like horizontal "instead" of "Horizontal"
thanks for your input. I suspect that the ball wouldn't move at all in the relevant direction if Horizontal or Vertical were misspelled. The ball responds correctly to input, it just moves on its on slowly forward even without input.
Answer by dethtoll · Apr 08, 2015 at 05:31 AM
This sounds very similar to this issue I found. There is a mystery force when using mesh colliders in Unity 5 (bug was not present in Unity 4.x)
One way I found to resolve this is to use box colliders instead of mesh colliders. In other words, the floor would sit 'on top' of a large, flat box collider.
Hi @dethtoll. I read your report of the issue and it sounds quite similar to the one I am experiencing. This may indeed be the problem. I hope it will soon get fixed. Thanks!
Answer by Axel429 · Dec 23, 2016 at 04:30 PM
Just keep the name of the horizontal and Vertical axes for the joystick and keyboard different it will work. If both the pairs are with same name then unity sends false coordinates thinking the joystick keys are being pressed and hence the ball moves own its own.