Skip to content

Instantly share code, notes, and snippets.

@SGTMcClain
Created April 2, 2020 00:36
Show Gist options
  • Save SGTMcClain/c369b86fe2a21bf0759d9bd65868b4e4 to your computer and use it in GitHub Desktop.
Save SGTMcClain/c369b86fe2a21bf0759d9bd65868b4e4 to your computer and use it in GitHub Desktop.
My Movement script
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