- Home /
Flight code not reading throttle axis
Hi guys,
I have the following code for a basic flight model (I will refine it later):
using UnityEngine; using System.Collections;
public class Player : MonoBehaviour {
float rollSpeed = 100.0f; //rolling rotation speed
float pitchSpeed = 100.0f; //vertical rotation speed
float yawSpeed = 100.0f; //horizontal rotation speed
float accelerate = 600.0f; //main engine thrust
float transZ = 600.0f; //maneuver thrust forward
float transY = 600.0f; //maneuver thrust vertical
float transX = 600.0f; //maneuver thrust horizontal
// Use this for initialization
void Start () {
animation["Flying"].wrapMode = WrapMode.Loop;
}
// Update is called once per frame
void Update () {
UpdateFunction();
}
void UpdateFunction()
{
Quaternion AddRot = Quaternion.identity;
float roll = 0;
float pitch = 0;
float yaw = 0;
float thrust = 0;
roll = Input.GetAxis("Roll") * (Time.deltaTime * rollSpeed);
pitch = Input.GetAxis("Pitch") * (Time.deltaTime * pitchSpeed);
yaw = Input.GetAxis("Yaw") * (Time.deltaTime * yawSpeed);
thrust = Input.GetAxis("Throttle") * (Time.deltaTime * accelerate);
AddRot.eulerAngles = new Vector3(-pitch, yaw, -roll);
rigidbody.rotation *= AddRot;
rigidbody.AddRelativeForce(0,0,thrust);
Vector3 AddPos = Vector3.forward;
AddPos = rigidbody.rotation * AddPos;
animation.CrossFade("Flying");
}
}
While the pitch, roll, and yaw clearly seem to work, the throttle axis doesn't seem to be working if I use the requisite keyboard keys (although I can't say for sure, since I haven't added a HUD with speed readings yet. Keep in mind that there's no translation if I turn off gravity for the player's rigidbody, so it probably doesn't work). These are the settings for the relevant axis:
Name: Throttle Positive Button: = Negative Button: - Alt Positive Button: i Alt Negative Button: k Gravity: 3 Dead: 0.001 Sensitivity: 3 Snap: Yes Type: Key or Mouse Button Axis: 3rd Axis Joy Num: Get motion from all joysticks
Thanks in advance, MachCUBED
Answer by MachCUBED · Mar 23, 2012 at 04:25 AM
I fixed it, it turns out it was working all right. I needed to increase the force added in order for it to work.