- Home /
Flight Script throws no errors but does nothing.
I'm making a game in which the player can fly, but my script is not working. It seems correct, throws no errors, but still does nothing. It looks like this:
#pragma strict
static var jumpHeight = 100000000000;
private static var flightParent : GameObject;
Debug.Log ("Flying");
public static function fly () {
var flightRigidbody : Rigidbody[];
if(flightParent == null) {
flightParent = GameObject.Find("FPSController");
Debug.Log ("Found Player to Fly");
}
flightRigidbody = flightParent.GetComponents.<Rigidbody>();
for (var parentFlight : Rigidbody in flightRigidbody) {
Debug.Log ("You Flapped your Wings");
parentFlight.velocity.y = jumpHeight;
Debug.Log ("Succesfull flight");
}
}
and is being called by:
if (Input.GetKey(KeyCode.Space))
{
if (MainScript.flying == true)
{
FlightScript.fly ();
}
}
All Debug.Logs are being thrown successfully. It may be noteworthy that the standard FPSCharacter is also being used in this project.
$$anonymous$$ost likely it has something to do with the fact that you're using a RigidBody with the standar FPS Controller, I haven't tried that in years but I think it's deadly to your game.
If I were you I wouldn't use the FPS Controller at all, it's very evil.
Also like what Eudaimonium said, you probably don't want to manually modify the velocity of your Rigidbody unless it's never moved on the y axis via Rigidbody other than that.
Also I forgot to mention, I'm not entirely sure but I think that jumpHeight variable is a too big number, try 10000 ins$$anonymous$$d. I'm not completely sure, though.
Answer by Eudaimonium · May 27, 2016 at 12:20 PM
Manually modifying the components of the velocity vector is a bad idea.
Use the provided AddForce function from the Rigidbody component. http://docs.unity3d.com/ScriptReference/Rigidbody.AddForce.html
Answer by Muhammad Salman · May 27, 2016 at 04:14 PM
Are you using any animation on it? Like there must be any animator attached to the character which stops it doing so. Add a animation or try it removing animator.
Your answer
Follow this Question
Related Questions
Making a flight script dependent on several variables activated by another script. 1 Answer
Attaching Main Camera to a GameObject 1 Answer
Override MouseLook/FirstPersonController 0 Answers
FirstPersonController script on Network 0 Answers
Restricting camera movement in first person camera? 0 Answers