- Home /
Making a pane controller with physics
I'm making an open world city game, and am adding some planes to it, but I cant figure out how to make the plane controller work properly. Currently it doesn't collide or get affected by gravity. I've tried just slapping a Rigidbody on, but that just messes everything up. What I'm trying to make is a plane controller similar to the one from GTA5, so you can fly around, hit stuff (I'll add damage later), and if you are travelling too slow, you fall. Does anyone know how to do that?
I have a plane controller, but it simply uses transform.forward to move the plane, so it ends up clipping through everything, and gravity has no affect on it.
Here's my current code:
public float forwardSpeed = 25f, turnSpeed = 7.5f;
public float currentForwardSpeed;
public float forwardAccel = 2.5f, turnAccel = 2f;
public float lookRotateSpeed = 90f;
private Vector2 lookInput, screenCentre, mouseDistance;
void Start()
{
check = this.gameObject.GetComponent<collisionCheck>();
screenCentre.x = Screen.width * 0.5f;
screenCentre.y = Screen.height * 0.5f;
}
// Update is called once per frame
void Update()
{
lookInput.x = Input.mousePosition.x;
lookInput.y = Input.mousePosition.y;
mouseDistance.x = (lookInput.x - screenCentre.x) / screenCentre.y;
mouseDistance.y = (lookInput.y - screenCentre.y) / screenCentre.y;
mouseDistance = Vector2.ClampMagnitude(mouseDistance, 1f);
transform.Rotate(mouseDistance.y * lookRotateSpeed * Time.deltaTime, mouseDistance.x * lookRotateSpeed * Time.deltaTime, 0f, Space.Self);
currentForwardSpeed = Mathf.Lerp(currentForwardSpeed, Input.GetAxisRaw("Vertical") * forwardSpeed, forwardAccel * Time.deltaTime);
transform.position = transform.position + (transform.forward * currentForwardSpeed * Time.deltaTime * -1);
if (Input.GetKey(KeyCode.A))
{
transform.Rotate(0, 0, turnSpeed * Time.deltaTime * -1);
}
if (Input.GetKey(KeyCode.D))
{
transform.Rotate(0, 0, turnSpeed * Time.deltaTime);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613050228im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
My player's movement is slippery 1 Answer
Changing wheel collider direction in Unity 5 0 Answers
Movement script breaks colliders 1 Answer
Player falls through rising platform? 4 Answers
Player Control. Roller Ball with Cube Acceleration. 1 Answer