Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

public float runSpeed = 5f; // controls player's speed

private float moveInput; // will tell the computer to move the player later on.

private Rigidbody2D rb; // this will be the rigidbody the forces will be  applied to.

private void Start () {

rb = GetComponent<Rigidbody2D>(); // the game needs to know which object to apply forces to; it won't automatically know it's supposed to move the player

}

private void FixedUpdate()

{

 moveInput = Input.GetAxis("Horizontal"); // Input.GetAxis("Horizontal")  is a shortcut you can use in unity to use the arrow keys/ A&D keys to move forward
  rb.velocity = new Vector2(moveInput * runSpeed, rb.velocity.y); // will cause the rigidbody to move depending on which buttons you press

}

/* This should get your character to move left and right,  but not up/down. If you want them to move freely up and down, write  :

moveInput = Input.GetAxis("Vertical"); right under  moveInput = Input.GetAxis("Horizontal"); . Jumping is a little trickier. 

since you need permission to use other people's work for this jam, I hereby declare that anyone participating in this gamejam can use this comment and it's contents to use in their games for whatever purpose. */

Thank you

Did it work the way you wanted it to?

I already had my own script but that help as for declaring the moveVelocity variable you needed a x and y and I couldn't find a solution. So thank you

I still have a problem though, the sprite moves down incredibly slowly (tried to change the gravity), it worked but would not touch the ground

(+1)

what i've done is this but the sprite would not touch the ground for some reason 

also I mean moveInput note velocity on the moveVelocity = new Vector2 (moveVelocity...) I mean (moveInput)

I don't think its because of the script though becuase i tested this on another sprite without the script so any suggestions what went wrong?

The box collider is maybe set too low. Try move it up in the editor without also move the sprite.