Search Unity

this code seems to not to work, im making a ball role game.

Discussion in 'Scripting' started by ncoy01, May 29, 2015.

  1. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class playercontroler : MonoBehaviour {
    5.  
    6.     public float speed;
    7.  
    8.     private Rigidbody rb;
    9.  
    10.     void Start()
    11.     {
    12.         rb = GetComponent<Rigidbody>();
    13.     }
    14.  
    15.     void FixedUpdate()
    16.     {
    17.         float moveHorizontal = Input.GetAxis ("Horizontal");
    18.         float moveVertical = Input.GetAxis ("Vertical");
    19.  
    20.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    21.  
    22.         rb.AddForce (movement * speed);
    23.     }
    24. }
     
  2. Juice-Tin

    Juice-Tin

    Joined:
    Jul 22, 2012
    Posts:
    244
    Is speed set to a high enough number?
     
  3. chubbspet

    chubbspet

    Joined:
    Feb 18, 2010
    Posts:
    1,220
    You are not giving speed a value.
     
  4. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    hw do you hive speed a value
     
  5. chubbspet

    chubbspet

    Joined:
    Feb 18, 2010
    Posts:
    1,220
    assign a value ion the Start function

    speed = 10;
     
  6. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    that didn't work at all
     
  7. chubbspet

    chubbspet

    Joined:
    Feb 18, 2010
    Posts:
    1,220
    Your script should work. Check a couple of things:
    Make sure your script is attached
    Make sure the rigidbody is attached and NOT set to "isKinematic"
    Make sure (in the inspector) that speed has a value and make that value higher.

    If this doesn't work, upload a package
     
  8. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    I cant see how to uplad a package
     
  9. NomadKing

    NomadKing

    Joined:
    Feb 11, 2010
    Posts:
    1,461
    Probably didn't work because it's set to 0 in the inspector.
     
    Last edited: May 29, 2015
  10. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    how do you upload a package into this
     
  11. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    I just made a video to show it