UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"create script that makes a character move around"
using UnityEngine; public class CharacterMovement : MonoBehaviour { public float moveSpeed = 5f; public float rotationSpeed = 200f; private Rigidbody rb; private Vector3 movement; private float rotation; // Start is called before the first frame update void Start() { rb = GetComponent<Rigidbody>(); } // Update is called once per frame void Update() { float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); movement = new Vector3(horizontal, 0, vertical); rotation = horizontal * rotationSpeed * Time.deltaTime; } // FixedUpdate is called once per fixed time interval void FixedUpdate() { MoveCharacter(); RotateCharacter(); } void MoveCharacter() { rb.velocity = movement * moveSpeed; } void RotateCharacter() { transform.Rotate(0, rotation, 0); } }