Making a double jump using functions (capx attached)

Get help using Construct 2

Post » Sun Mar 20, 2016 6:45 am

Wondering if anyone can help me fix up this double jump. I am trying to make it using functions. I have it working a bit but I've obviously messed something up because it's not working the way it should.

At the moment, the player will do a double jump if he is falling (if he walks off the platform), but he won't double jump after a standing jump.

If I change the 'Compare instance variable' for the 'doubleJump' variable to 'less than or equal to 1' rather than 'less than 1' as it now, then the player will double jump following a standing jump, but in that case, he will do two double jumps when he is falling (if he walks off the platform).

I want the player to be able to double jump once following a regular standing jump, and double jump once if he is falling after walking off a platform.

I hope that makes sense. Here is the capx file

By the way, jump is the 'Z' key.

Thanks for any help.
B
71
S
51
G
60
Posts: 400
Reputation: 37,884

Post » Sun Mar 20, 2016 10:47 am

The biggest problem is that statement: "By the way, jump is the 'Z' key."

It is not. Why ?

Well, the Platform-Behaviour is still running in 'Default Controls'. That makes the Up-Arrowkey the JumpKey.
If you want different. Then you have to change the 'Default Controls' property from 'yes' to 'no' in the Platform-Behaviour.

After that you are free to use 'z' as the JumpKey. But that means also that you have to make events for Left and Right. Once done that, everything else will be easy and work as you expect it to do.

Maybe follow this Tut for a minute:
/tutorials/455/platformer-enhancements-double-jump/page-1
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sun Mar 20, 2016 11:15 am

Why can't you just use the default double jump ?
All you need is this
Image
and this
Image
B
14
S
2
Posts: 35
Reputation: 789

Post » Sun Mar 20, 2016 11:43 am

@laypax, I'll probably just end up using the default double jump behavior if I can't get this working. Im trying to do it with functions, basically because I think functions are like 'best practice'. I bought a game kit from the scirra store which Im using to try and learn, and all the player's movement mechanics are built out using functions to control everything: moving left and right, jumping, controlling the player shooting etc. So I am trying to build in some additional player mechanics myself, using the same system that the author has in place.

I found some double jump tutorials, for example the one 99Instances2Go mentioned above: Platformer Enhancements - Double Jump, and tried to build that methodology into a function... It kind of works, but not quite.

@99Instances2Go, well, I dont think adding custom jumping mechanics to the 'Z' key should clash with the platform behavior should it? The arrow keys still work, and the 'Z' key works for a normal jump, and it even works for a double jump, I just have something screwed up with how the instance variable works...

Ill keep playing with it. Thanks for the replies guys.
B
71
S
51
G
60
Posts: 400
Reputation: 37,884

Post » Sun Mar 20, 2016 2:28 pm

No, there is no clash. I did't expect you to read it like that. Even though, i could have written that, there are languages i write much better in.

I tried to lead you in finding out the things by yourself.

The default controls do what you need: A double jump when in the air.

If you change one of the default controls, you need to take control of them all. And suddenly, as by magic, you will see the solution just by yourself.

If i understand you correct, you want a double jump when in the air only if 'z' is pressed. In that case you also need to alter the 'up arrow', so it dont double jump. Easy as that, when you take control.

https://
drive.google.com/open?id=0B1SSuCVV8v74MjR5NWJWV3VpU1U

Not that i would like play this way. I still prefer default to play.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sun Mar 20, 2016 2:36 pm

Of course if u just want 'z' to be the jump key. Use the custom keys. And avoid a mess by taking control of them all.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Mar 23, 2016 3:38 am

I actually managed to get this working (amazed at self :-0). And it was such a simple thing that was stopping it from working.
All I had to do was change the order of the events. Originally I had the events calling the 'Player_Jump' function come first in the event sheet. All I had to do was rearrange things so the events calling the 'Player_DoubleJump' function were above the events calling the 'Player_Jump' and it started working exactly how I wanted! I have no idea why the events needed to be arranged that way... to my mind it shoudn't make a difference. But what do I know!

Yay :D

fixed capx
B
71
S
51
G
60
Posts: 400
Reputation: 37,884

Post » Wed Mar 23, 2016 4:11 am

Actually, event ordering is important in certain cases as event sheets run top to bottom every tick, so events at the very top will get executed first. Also, some events can clash with each other, depending on the order they're in.

Also, made some changes if you don't mind (you're free to use this):
https://dl.dropboxusercontent.com/u/589 ... fixed.capx

You might also want to make the height of the double jump a bit more, as I found it slightly difficult to reach the drop through platforms from below them.
Zelda Gamekit (my project)



Example capxs:

Zelda-Style Inventory

Zelda Health

3-saveslot system

[url=https://www.dropbox.com/s/d4396pwak0oh7q6/ZeldaDialogueSystem.capx?dl=0]Zelda-like Dialogue[
B
51
S
24
G
30
Posts: 534
Reputation: 19,620

Post » Wed Mar 23, 2016 4:27 am

Hi thanks for that feedback and for the edits.. So you disabled default controls and made functions for Right and Left I see. I actually have movement functions already working in my more developed prototype (not the test capx's I posted here), but I note your tip about leaving 'Player is on floor' out of any player movement controls. Thanks for that.

As for the order of events.. I know I have read in various tutes that event order matters, its just in this case, i can't really see why. It seems to me that it should work the same regardless of whether the input for 'double jump' comes before or after 'jump'. Not sure why it matters in this case. But never mind, its working so I am happy.

My next challenges are: making a wall jumping behavior using functions & making a dash attack using functions.

I have the wall jump working in a simplistic way, but not yet using functions. Dashing is hard though.
B
71
S
51
G
60
Posts: 400
Reputation: 37,884

Post » Wed Mar 23, 2016 4:33 am

Maybe because since you have to jump first in order to double jump, jump functions have to come first, order wise?
I could try to help you with the wall jumping function and dash one too, soon.
Zelda Gamekit (my project)



Example capxs:

Zelda-Style Inventory

Zelda Health

3-saveslot system

[url=https://www.dropbox.com/s/d4396pwak0oh7q6/ZeldaDialogueSystem.capx?dl=0]Zelda-like Dialogue[
B
51
S
24
G
30
Posts: 534
Reputation: 19,620

Next

Return to How do I....?

Who is online

Users browsing this forum: TRMG and 36 guests