x


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

more ▼

asked Mar 22 '12 at 04:19 AM

MachCUBED gravatar image

MachCUBED
116 22 32 37

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I fixed it, it turns out it was working all right. I needed to increase the force added in order for it to work.

more ▼

answered Mar 23 '12 at 04:25 AM

MachCUBED gravatar image

MachCUBED
116 22 32 37

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5085
x1794
x954
x50
x35

asked: Mar 22 '12 at 04:19 AM

Seen: 521 times

Last Updated: Mar 23 '12 at 04:25 AM