I am trying to figure out how to rotate a plane about its origin in 3D space. Here is the last iteration of the code I am working with; the plane does not move.
using UnityEngine;
public class PlaneController : MonoBehaviour
{
public float speed = 5f; // Speed of movement
public float rotationSpeed = 100f; // Speed of rotation
private void Start()
{
// Create a new GameObject for the plane
GameObject plane = new GameObject("Plane");
// Add BoxCollider component to the plane
BoxCollider collider = plane.AddComponent<BoxCollider>();
collider.size = new Vector3(1f, 0.01f, 1f);
collider.center = Vector3.zero;
// Set the plane's position and rotation
plane.transform.position = Vector3.zero;
plane.transform.rotation = Quaternion.identity;
// Set the plane as a child of the current GameObject
plane.transform.parent = transform;
// Move and rotate the plane based on input
void Update()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
float rotate = Input.GetAxis("Rotate");
// Calculate movement and rotation
Vector3 movement = new Vector3(moveHorizontal, 0f, moveVertical) * speed * Time.deltaTime;
Quaternion rotation = Quaternion.Euler(0f, rotate * rotationSpeed * Time.deltaTime, 0f);
// Apply movement and rotation to the plane
plane.transform.Translate(movement, Space.World);
plane.transform.Rotate(rotation.eulerAngles, Space.World);
}
}
}
UPDATE:
I updated my code to this, and the plane is still not moving. Any help in what I am doing incorrectly would be greatly appreciated.
using UnityEngine;
public class PlaneController : MonoBehaviour
{
public float speed = 5f; // Speed of movement
public float rotationSpeed = 100f; // Speed of rotation
private void Update()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
float rotate = Input.GetAxis("Rotate");
// Calculate movement and rotation
Vector3 movement = new Vector3(moveHorizontal, 0f, moveVertical) * speed * Time.deltaTime;
Quaternion rotation = Quaternion.Euler(0f, rotate * rotationSpeed * Time.deltaTime, 0f);
// Apply movement and rotation to the plane
transform.Translate(movement, Space.World);
transform.Rotate(rotation.eulerAngles, Space.World);
}
}


Update()a local function ofStart()? \$\endgroup\$Input.GetAxis("Rotate")? \$\endgroup\$