- Home /
Question by
LCK6180G · Jan 23, 2017 at 01:09 PM ·
unity 5scripting problemunity5collision detectionscriptingproblem
where have i went wrong in my script (unity 5)
hello, im trying to make a script for a simple flight control using torques (as im not aiming realism) and as this is unity 5 im super confused with what i'm doing since most of the scripts and guides i use might be older and is designed for unity 4, there is just some things i cant find an answer to make it work or atleast compile in my script, maybe someone could help me here
#pragma strict
public var pitch : float = 35f;
public var bank : float =12f;
public var yaw : float =3f;
public var gturn : float =3f;
//speed is more like thrust it seems, but meh too lazy to change any
var speed : float;
var speedincrease : float;
var speeddecrease : float;
var Maxspeed : int;
var Minspeed : int;
var Obj : Rigidbody;
//for ground/air control (confused to where to put it)
var taxi : GameObject;
var rway : GameObject;
var gnd : GameObject;
function Start () {
InvokeRepeating("Speed", .1, .1);
}
//taxi control (if it works -which doesnt)
function OnCollisionEnter (col : Collision)
{
//aileron
if (col.gameObject.name == var taxi )//use for the taxiway
{
if (Input.GetKey("right")){
GetComponent.<Rigidbody>().AddTorque(-transform.forward * gturn );
}
if (Input.GetKey("left")){
GetComponent.<Rigidbody>().AddTorque(transform.forward * gturn );
}
//rudder
if (Input.GetKey("z")){
GetComponent.<Rigidbody>().AddTorque(-transform.up * gturn );
}
if (Input.GetKey("c")){
GetComponent.<Rigidbody>().AddTorque(transform.up * gturn );
}
}
}
//runway control (works only on runway, elevator should deploy at "certain" speed not implemented yet because im confused)
function OnCollisionEnter (col : Collision)
{
//aileron
if (col.gameObject.name == var rwar )//use for the runway
{
if (Input.GetKey("right")){
GetComponent.<Rigidbody>().AddTorque(-transform.forward * gturn );
}
if (Input.GetKey("left")){
GetComponent.<Rigidbody>().AddTorque(transform.forward * gturn );
}
//rudder
if (Input.GetKey("z")){
GetComponent.<Rigidbody>().AddTorque(-transform.up * gturn );
}
if (Input.GetKey("c")){
GetComponent.<Rigidbody>().AddTorque(transform.up * gturn );
}
//elevators
if (Input.GetKey("down")){
GetComponent.<Rigidbody>().AddTorque(-transform.right * pitch );
}
if (Input.GetKey("up")){
GetComponent.<Rigidbody>().AddTorque(transform.right* pitch );
}
}
}
//air control (if it works -which doesnt)
function OnCollisionExit (col : Collision)//not colliding with the 2 object, aka taxi and runway to work
{
//elevators
if (Input.GetKey("down")){
GetComponent.<Rigidbody>().AddTorque(-transform.right * pitch );
}
if (Input.GetKey("up")){
GetComponent.<Rigidbody>().AddTorque(transform.right* pitch );
}
//ailerons
if (Input.GetKey("right")){
GetComponent.<Rigidbody>().AddTorque(-transform.forward * bank );
}
if (Input.GetKey("left")){
GetComponent.<Rigidbody>().AddTorque(transform.forward * bank );
}
//rudder
if (Input.GetKey("z")){
GetComponent.<Rigidbody>().AddTorque(-transform.up * yaw );
}
if (Input.GetKey("c")){
GetComponent.<Rigidbody>().AddTorque(transform.up * yaw );
}
}
//ends here currently, also placeholder and space, my head's steaming
//something's missing here: speed limiter and speed=heading not momentum along with the speedo
function Speed (){
if (Input.GetKey("q")){
Mathf.Repeat(1,Time.time);
speed=speed+speedincrease;
}
if (Input.GetKey("a")){
Mathf.Repeat(1,Time.time);
speed=speed-speeddecrease;
}
}
function Update () {
var spd = Obj.velocity.magnitude;
Obj.GetComponent.<Rigidbody>().AddRelativeForce(0,0,speed);
if(Maxspeed<=speed){
speed=Maxspeed;
}else{
speed=speed;
}
if(Minspeed>=speed){
speed=Minspeed;
}else{
speed=speed;
}
}
//currently end of the line, either i mix all the scripts or mix em in one big bag of mess
Comment
Your answer
Follow this Question
Related Questions
Script sets same value to other script in all objects instead of just one. 1 Answer
Collider with rigidbody does not register collision with terrain 2 Answers
Reference DLL's 1 Answer
Raycast do not detect when distance is closer or further than the max distance 1 Answer
Refresh panel with prefab contained value from json that created using array 0 Answers