Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Roll-a-Ball Just a Little Extra Help Please?

Discussion in 'Getting Started' started by TheFramPlay, Mar 1, 2015.

  1. TheFramPlay

    TheFramPlay

    Joined:
    Mar 1, 2015
    Posts:
    2
    I keep encountering the same problem over and over and over and over again. I have the script for the player to move the ball, but every time I press play, it moves on it's own, but I can still control it, but it will constantly keep moving upleft away from the camera whilst looking at the ball on the grid. I check my script, and it's correct, I change it a little (I'm still a beginner script writer) and I corrupt my script. I just can't seem to not get the ball to move on it's own. I really need help.

    using UnityEngine;
    using System.Collections;

    public class PlayerController : MonoBehaviour
    {

    void FixedUpdate() {
    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVertical = Input.GetAxis ("Vertical");

    Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

    rigidbody.AddForce (movement);
    }
    }
     
  2. Ramsdal

    Ramsdal

    Joined:
    Oct 18, 2013
    Posts:
    251
    There is a little talk about that in this thread as well perhaps it is something with the controls. I guess you have attached the script to the ball and given the ball a rigidbody obviously.
     
  3. TheFramPlay

    TheFramPlay

    Joined:
    Mar 1, 2015
    Posts:
    2
    The weird thing is, it's all attached, controls are configured. Controls.PNG
     
  4. Trickett

    Trickett

    Joined:
    Mar 1, 2015
    Posts:
    1
    Hm. I think the method AddForce method just works that way. It is continuously applying a force to the rigidbody.
    I think you can get it to stop once you stop pressing the input control by increasing the angular drag on the rigidbody. Drag might be useful too but it slows the object down a lot.
    If it's moving that way right from the start without any input, maybe your plane is on a slight rotation?
    AddForce is probably not the best way of moving characters that aren't spherical. x:

    This video is helpful in explaining AddForce.
    The Scripting API is helpful too sometimes.