Created
April 2, 2020 00:36
-
-
Save SGTMcClain/c369b86fe2a21bf0759d9bd65868b4e4 to your computer and use it in GitHub Desktop.
My Movement script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class PlayerMovement : MonoBehaviour | |
{ | |
[SerializeField] | |
private float speed = 5; | |
private Rigidbody2D rbody2D; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
rbody2D = GetComponent<Rigidbody2D>(); | |
} | |
// Update happens regardless of framerate | |
private void FixedUpdate() | |
{ | |
float moveHorizontal = Input.GetAxis("Horizontal"); // a number between -1 and 1 | |
float moveVertical = Input.GetAxis("Vertical"); // a number between -1 and 1 | |
Vector2 movement = new Vector2(moveHorizontal, moveVertical); | |
//rbody2D.velocity = movement * speed; | |
rbody2D.AddForce(movement * speed); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment