NovaCode

Basic Character Movement

Oct 23rd, 2025
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.46 KB | Source Code | 0 0
  1. using UnityEngine;
  2.  
  3. public class PlayerMovement : MonoBehaviour
  4. {
  5.     public float speed = 5f;
  6.     CharacterController controller;
  7.  
  8.     void Start() => controller = GetComponent<CharacterController>();
  9.  
  10.     void Update()
  11.     {
  12.         float x = Input.GetAxis("Horizontal");
  13.         float z = Input.GetAxis("Vertical");
  14.         Vector3 move = transform.right * x + transform.forward * z;
  15.         controller.Move(move * speed * Time.deltaTime);
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment