Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Object won't move

Discussion in 'Physics' started by shadowmasterx99, Jul 22, 2015.

  1. shadowmasterx99

    shadowmasterx99

    Joined:
    Feb 8, 2015
    Posts:
    5
    I am creating my own FPS Controller because a) I could use the experience and b) the one provided by Unity attached sticks of butter to their feet. The only problem is, I can't get it to move.

    So, here's my code.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerScript : MonoBehaviour {
    5.  
    6.     public float speed;
    7.     public float jumpForce;
    8.  
    9.     bool jumping;
    10.     Rigidbody playerRigidbody;
    11.  
    12.     void Awake () {
    13.         playerRigidbody = GetComponent <Rigidbody> ();
    14.     }
    15.  
    16.     void FixedUpdate () {
    17.         if (Input.GetKey("Space") && !jumping) {
    18.             playerRigidbody.AddForce(transform.up * jumpForce);
    19.             jumping = true;
    20.         }
    21.         if (Input.GetKey("w")) playerRigidbody.AddForce(transform.forward * speed);
    22.         if (Input.GetKey("a")) playerRigidbody.AddForce(-transform.right * speed);
    23.         if (Input.GetKey("s")) playerRigidbody.AddForce(-transform.forward * speed);
    24.         if (Input.GetKey("d")) playerRigidbody.AddForce(transform.right * speed);
    25.  
    26.     }
    27. }
    28.  
    Also (because I know someone's going to ask), I have already tried changing the speed and jumpForce values.
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    what values are you using?

    what are the rigidbody settings?
     
  3. shadowmasterx99

    shadowmasterx99

    Joined:
    Feb 8, 2015
    Posts:
    5
    As stated in the original post, I have already changed the values of speed and jumpForce to several different values.

    I have also changed each of the rigidbody settings as well.
     
  4. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    meh
     
    Last edited: Jul 23, 2015
  5. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Try changing three of the if(Input.Getkey... in to a comment, see, if that changes anything
     
  6. DerpMerf

    DerpMerf

    Joined:
    Jan 1, 2014
    Posts:
    33
    Holy Jesus. Whatever happened to Input.GetAxis()? Is that not a thing in the latest update (intense sarcasm)? That is much easier than what you are doing now. Here:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerScript : MonoBehaviour {
    5.     public float speed;
    6.     public float jumpForce;
    7.  
    8.     bool jumping;
    9.     Rigidbody playerRigidbody;
    10.  
    11.     void Awake() {
    12.         playerRigidbody = Get
    13.     }
    14. }