- Home /
Making a player controller for a jet fighter
Hi there!
My name is D'Carlo Murphy and this maybe the second time I'm asking a question here so if I'm doing anything wrong just let me know.
So a little background to really understand my situation. I'm 18 getting into game development, had a few hiccups but I've found a 'simple' game I could try for my first ever game. I'm...familiar with C#, I understand what variables and functions are. Trying to understand coroutines and more stuff so I'm not a newborn to C# but more of a toddler.
Now my real problem. I'm trying to make a player controller script for an airplane. So far I've got my little plane I named "The StarChaser" with a rigidbody with use gravity turned off just for now for simplicity sake. I also have the main camera as a child to the plane so it can follow it (although I'm sure when my plane starts turning that this simple fix will be obsolete) along with really simple C# script that basically makes the plane go forward and that's basically it for controls.
What I'm aiming for is sort of plane controls that a game like War Thunder has for their planes. I'm not going for complexity (cause it is supposed to be a arcade voxel themed game) but where my plane would roll and yaw and follow the player's mouse cursor. Any ideas how I would get this sort of affect?
I'll also leave the code I've typed up so far below, don't laugh I'm still on training wheels lol.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Controls : MonoBehaviour {
//Demo!!!!!!
//Yes I should leave more comments...
//Forward is Left, Backward is Right,
public float maxSpeed;
public float decAltSpeed;
public float incAltSpeed;
public float curSpeed;
public float appliedSpeed;
public float airBrakeForce;
private Rigidbody myRigid;
void Start ()
{
myRigid = GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
curSpeed = myRigid.velocity.x;
if(curSpeed <= maxSpeed)
{
curSpeed = maxSpeed;
Debug.Log("We're going too fast!");
}
if(curSpeed >= maxSpeed)
{
curSpeed = maxSpeed;
}
if (Input.GetKey("w"))
{
//Applying forward speed with key press "W"
myRigid.AddRelativeForce(Vector3.left * appliedSpeed);
if (curSpeed >= incAltSpeed)
{
myRigid.AddRelativeForce(Vector3.up * 5);
}
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612163143im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Face Direction Movement using CharacterController 1 Answer
controller.Move doesn't stay grounded when walking down slope 3 Answers
Character controller just spinning. 0 Answers
Distribute terrain in zones 3 Answers