- Home /
gravity gets too strong and plane falls to the ground help
i have an aeroplane and when i fly it it works normally but after a while the gravity gets really strong and it just crashes, i am using transform.translate to move, so the rigidbody is probably falling down and the transform.translate doesnt stop it. can someone change this script to one that will work?
var movespeed = 0;
var turn = 0;
var noseup = 0;
var F22Model : GameObject;
var explosion : GameObject;
var crashed = 1;
var maxspeed = 600;
var abletomove = 1;
var eject = 0;
var stopeject = 0;
function Update () {
var lift = movespeed * 0.5;
transform.Translate(Vector3.right * Time.deltaTime * movespeed);
transform.Rotate(Vector3.left * Time.deltaTime * turn);
transform.Translate(Vector3.up * Time.deltaTime * lift);
transform.Rotate(Vector3.forward * Time.deltaTime * noseup);
transform.Translate(Vector3.up * Time.deltaTime * eject);
if (Input.GetKey("up"))
if (abletomove == 1)
movespeed += 1;
if (Input.GetKey("down"))
if (abletomove == 1)
movespeed -= 0.01;
if (Input.GetKey("a"))
if (abletomove == 1)
turn -= 15;
if (Input.GetKey("d"))
if (abletomove == 1)
turn += 15;
if (turn <= 0)
turn += 5;
if (turn >= 0)
turn -= 5;
if (noseup <= 0)
noseup += 5;
if (noseup >= 0)
noseup -= 5;
if (Input.GetKey("s"))
if (abletomove == 1)
noseup += 10;
if (Input.GetKey("w"))
if (abletomove == 1)
noseup -= 10;
if (movespeed >= maxspeed){
movespeed = maxspeed;
}
if(stopeject >= 300){
eject = 0;
}
if (crashed == 0)
if (stopeject <= 300){
eject += 20;
}
}
function OnCollisionEnter(thing : Collision) {
if (thing.collider.tag == "Terrain") {
if (crashed == 1) {
Destroy (F22Model);
Instantiate (explosion, transform.position, transform.rotation);
crashed = 0;
movespeed = 0;
stopeject += eject;
turn = 0;
noseup = 0;
maxspeed = 0;
abletomove = 0;
transform.Rotate(Vector3.forward * -90);
}
}
}
thanks
Either get rid of the rigidbody component, or rewrite your script entirely. I'm afraid I can't really help you here- you can't have inbuilt collisions at the same time as managing all your movement from transform.Translate calls. Either manage collisions yourself as well, or rethink your script to one which works with the rigidbody system ins$$anonymous$$d of against it.
I won't write your script for you, since this is basically completely rewriting it.
Your answer
Follow this Question
Related Questions
how to make an object "the target" when you click on it 3 Answers
function error 1 Answer
manabar doesnt work 1 Answer
enemy is destroyed at the start instead of when health is 0 1 Answer
Low Poly Water 4 Answers