Skip to content

Instantly share code, notes, and snippets.

@nabesi777
Created September 13, 2018 15:23
Show Gist options
  • Save nabesi777/168807235668da12de43a97b8516fe8c to your computer and use it in GitHub Desktop.
Save nabesi777/168807235668da12de43a97b8516fe8c to your computer and use it in GitHub Desktop.
PlayerMove [Rigidbody] C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
public float speed = 3f;
float moveX = 0f;
float moveZ = 0f;
Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
moveX = Input.GetAxis("Horizontal") * speed;
moveZ = Input.GetAxis("Vertical") * speed;
Vector3 direction = new Vector3(moveX, 0, moveZ);
}
void FixedUpdate()
{
rb.velocity = new Vector3(moveX, 0, moveZ);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment