gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
can you create for me a unity script for a flying player controller
- User
can you create for me a unity script for a flying player controller
- Assistant
Sure! Here's a basic Unity script for a flying player controller:
csharpusing UnityEngine; public class FlyingPlayerController : MonoBehaviour { public float speed = 10f; public float rotationSpeed = 2f; private Rigidbody rb; private void Awake() { rb = GetComponent<Rigidbody>(); rb.useGravity = false; // Disable gravity for flying } private void FixedUpdate() { // Get input axes float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); // Movement calculations Vector3 moveDirection = new Vector3(moveHorizontal, 0, moveVertical).normalized; Vector3 moveForce = moveDirection * speed; // Apply movement force rb.AddForce(moveForce); // Rotate player based on mouse movement float rotationY = Input.GetAxis("Mouse X") * rotationSpeed; transform.Rotate(0, rotationY, 0); } }