UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"create a character"
using UnityEngine; public class Character : MonoBehaviour { public float moveSpeed = 5f; public float rotationSpeed = 100f; private Rigidbody rb; // Start is called before the first frame update void Start() { rb = GetComponent<Rigidbody>(); } // Update is called once per frame void Update() { /* Move character */ float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); rb.AddForce(movement * moveSpeed); /* Rotate character */ float rotation = Input.GetAxis("Mouse X") * rotationSpeed * Time.deltaTime; transform.Rotate(0, rotation, 0); } }