I have a script for basic movement that works, but I want to be able to steer the players horizontal movement while midair. I also would like to be able to determine the force or the height of the jump by how long I hold the jump button.
Here's my working movement script so far:
public class Player_movement : MonoBehaviour
public float f_speed;
public float f_jumpSpeed;
public float f_gravity;
private Vector3 v3_moveDirection = Vector3.zero;
private CharacterController controller;
void Awake ()
controller = GetComponent<CharacterController>();
void Update ()
v3_moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
v3_moveDirection *= f_speed;
v3_moveDirection.y = f_jumpSpeed;
v3_moveDirection.y -= f_gravity * Time.deltaTime;
controller.Move(v3_moveDirection * Time.deltaTime);
Answer by AndreasDp
Oct 21, 2012 at 03:09 PM
i get this error. NullReferenceException: Object reference not set to an instance of an object PlayerMovement.Update () (at Assets/PlayerMovement.cs:19) -------- How can i fix it
Did you add a Character Controller?
Answer by fdfragoso
Jul 19, 2013 at 03:28 AM
Change your line 14 to: controller = this.GetComponent(); Put this script inside who will make the action of movement.
Answer by GameFist132
Oct 24, 2015 at 09:25 PM
maybe this script was from an older version?
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
9 People are following this question.
Making a bubble level (not a game but work tool)
2D Character Switching HELP!
No movement when animation plays (2d)
Changing player's moving direction
How can I make a collision sensitive teleporter for a 2D game #c