Generation

generate functionSun, 21 May 2023

A fps character controller with joystick

void ControlCharacter(float horizontal, float vertical) { // Create a vector that the controller's velocity should match Vector3 targetDirection = new Vector3(horizontal, 0f, vertical); // Create a rotation based on the input Quaternion targetRotation = Quaternion.LookRotation(targetDirection, Vector3.up); // Lerp the player's rotation to match the target's rotation transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, rotateSpeed * Time.deltaTime); }

Questions about programming?Chat with your personal AI assistant