Skip to content

Instantly share code, notes, and snippets.

@aviralgoel
Last active June 4, 2019 08:32
Show Gist options
  • Save aviralgoel/132cd87b44cbbb02e5cd7d558f7f12a5 to your computer and use it in GitHub Desktop.
Save aviralgoel/132cd87b44cbbb02e5cd7d558f7f12a5 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0, moveVertical);
rb.AddForce(movement * speed);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment