Hi everyone, I’m trying to script basic flight controls for a flight sim I would like to make. I can’t seem to get the object to move forward. I want the player to be able to control the speed using the keypad + and - keys. Making the speed increase or decrease and stop moving. This is the script I have, I’m not getting any errors but it just doesn’t seem to work at all.
Any help would be greatly appreciate or even suggestions to make it better.
using UnityEngine;
using System.Collections;
public class PlayController : MonoBehaviour
{
//Variables for speed control
public float curSpeed;
public float maxSpeed = 1200;
public float minSpeed = 0;
void Start ()
{
CurSpeed ();
}
void FixedUpdate ()
{
if (Input.GetKeyDown (KeyCode.KeypadPlus))
{
rigidbody.AddForce (Vector3.forward * curSpeed);
}
if (Input.GetKeyDown (KeyCode.KeypadMinus))
{
rigidbody.AddForce (Vector3.forward * curSpeed);
}
transform.Rotate (Input.GetAxis("Vertical"), 0.0f,
-Input.GetAxis(“Horizontal”));
}
void CurSpeed()
{
float incSpeed = 5;
float decSpeed = 5;
if (curSpeed > 0 && curSpeed < maxSpeed)
{
curSpeed += incSpeed;
}
else if (curSpeed == maxSpeed)
{
curSpeed = maxSpeed;
}
if (curSpeed <= maxSpeed && curSpeed > minSpeed)
{
curSpeed -= decSpeed;
}
else if (curSpeed == minSpeed)
{
curSpeed = minSpeed;
}
}
}