- Home /
Parachute/Glide
For my FPS I need a parachute or glide script but I cant get it to work..
I tried using a courotine because I couldnt detect when I was falling, so if I jumped up the parachute would still be able to be used.
if(Input.GetKey (KeyCode.P)) {
if (parachutefall==true) {
gravity = 1;
flying = true;
inAirControl = 0.0001;
} else if(gravity==1) {
gravity = 25;
rigidbody.drag = 0;
flying = false;
inAirControl = 0.01;
}
}
if (grounded == true) {
gravity = 25;
flying = false;
inAirControl = 0.01;
parachutefall = false;
}
if (grounded == false) {
StartCoroutine(WaitAndPrint(2.0));
}
function OnGUI(){
if(onLadder && !canClimb)
GUI.Label(Rect(Screen.width - (Screen.width/1.7),Screen.height - (Screen.height/2 - 170),800,100),"Press key >>E<< to Climb");
if (flying == true)
GUI.Label(Rect(Screen.width - (Screen.width/1.7),Screen.height - (Screen.height/2 - 170),800,100),"Press >>P<< to Cut Loose");
//if (parachutefall == true)
//GUI.Label(Rect(Screen.width - (Screen.width/1.7),Screen.height - (Screen.height/2 - 170),800,100),"Press >>P<< to Use Parachute");
}
function WaitAndPrint (waitTime : float) {
yield WaitForSeconds (1);
parachutefall = true;
}
Answer by MattMorris · Feb 20, 2014 at 05:23 AM
What I would do is have all your falling logic be placed in a different script or function IE:
function ParachuteLogic()
{
if(parachuteIsOpen) //this is short hand for parachute == true
{
}
}
Then within your update keep checking for that P button press so:
function Update()
{
if(Input.GetKey(KeyCode.P))
{
parachuteIsOpen = true;
}
}
This helps keep things seperated and extendable. Its now easier to add your jump into the mix to detect for that. So now we will update our update function.
function Update()
{
if(Input.GetKey(KeyCode.P))
{
parachuteIsOpen = true;
}
if(Input.GetKey(KeyCode.Space))
{
playerIsJumping = true;
}
}
We can now take our same though process as keeping things compartimentalized and seperate and use that for our player jump. So in a new function we can do something like this:
function Player()
{
if(playerIsJumping)
{
var timeSinceJump : int += Time.deltaTime; // you could us this as your timmer
}
}
You also said you didn't want to allow the user to activate the parachute if the user jumped so you can now simple do this in that update function:
function Update()
{
if(Input.GetKey(KeyCode.P))
{
if(!playerIsJumping) // this is shorthand for playerIsJumping == false
{
parachuteIsOpen = true;
}
}
if(Input.GetKey(KeyCode.Space)) // space is a common jump button in games, but this can be remapped.
{
playerIsJumping = true;
}
Player(); // make sure anything that uses time is included in your update function
}
I think the majority of your problem is not viewing things as individual steps and breaking it down into those steps. Not sure exactly what your problem was, but I hope this answered your parachute opening while jumping problem. Let me know if you have any more questions or need anymore help!
i tried to implement this in a new script i couldnt get it to work..
Your answer
Follow this Question
Related Questions
How to make sure that my cube can only jump when in contact with the ground 2 Answers
I do not want to fly a car 0 Answers
Trying to create glide effect 1 Answer
Problems making a glider 3 Answers
Is there a way to smoothly transition between two floats, with it slowing down towards the end 1 Answer