UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"Script a player movement"
using UnityEngine; public class PlayerMovement : MonoBehaviour { public float moveSpeed = 5f; public Rigidbody rb; private Vector3 moveDirection; // Update is called once per frame void Update() { float moveX = Input.GetAxis("Horizontal"); float moveZ = Input.GetAxis("Vertical"); moveDirection = new Vector3(moveX, 0, moveZ).normalized; } // FixedUpdate is called at a fixed interval and is independent of frame rate void FixedUpdate() { rb.MovePosition(rb.position + moveDirection * moveSpeed * Time.fixedDeltaTime); } }