holding down jump makes jump bigger

Get help using Construct 2

Post » Sat May 05, 2012 12:04 pm

Hi,

i am creating a one click jumping game, what i want is for the player to jump higher the longer they hold the jump key down.

At the moment the way i have it working is that when they hold down the jump key it adds power to the sump strength and then when they release the button the player jumps. The strength being set by how long you held the key down for.

What i want to do is when the jump button is pressed the player jumps immediately and stays in the air until they release the key (up to a certain maximum jump strength. So the longer they hold the jump button down for while in flight the higher they will jump.

There are some other posts on something similar but none of them actually seem to do this... any help?
B
25
S
7
G
5
Posts: 185
Reputation: 5,056

Post » Sat May 05, 2012 2:01 pm

This is just how I would try..

Let's say the maximum jump height you want is 50

sysytem for every tick if jump button is down and maximum jump height is less than 50 add 1 to maximum jump height.

could that work?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
53
S
16
G
8
Posts: 6,157
Reputation: 19,744

Post » Sat May 05, 2012 2:17 pm

I tend to do this the same way the old Sonic games did.
When the player clicks to jump, set the vertical speed to, say, -10. Then when they release, check to see if the speed is less than -3. If it is, set it to -3. If it isn't, don't do anything.
You'll want to fine-tune those numbers a lot depending on different aspects of your game like sprite size and all that though.
B
62
S
26
G
12
Posts: 122
Reputation: 11,330

Post » Sat May 05, 2012 2:31 pm

PixelMonkey has it right. The simplest way to do this is to add an event that sets the vertical speed to 0 when the jump button is released. This makes the character start falling as soon as the button is released. THe transition can be a bit harsh, so that's why PM gave the -3 value. That makes the transition to fall smoother.
B
15
S
2
G
3
Posts: 45
Reputation: 2,638

Post » Sat May 05, 2012 2:37 pm

Yeah, perhaps I should elaborate more on what the numbers actually do. =b
The 10 is the speed at which the jump starts, so for a higher jump set that one higher.
The -3 is the speed that it is set to to slow the jump. A 0 would stop the jump immediately, but it tends to look unrealistic for all movement to stop entirely. Also, putting in a negative value will allow you to have small jumps if the player releases the mouse immediately after clicking.
B
62
S
26
G
12
Posts: 122
Reputation: 11,330

Post » Sat May 05, 2012 6:48 pm

This is what I do, and it is variable (so not just 2 heights of jump)
Basically, if the player is jumping, and jump key is released, and yvector < 0, just divide yvector by some number (2 is a good start).
This will give variable jump height.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Sat May 05, 2012 7:36 pm

@pixelmonkey: hi, that sounds like exactly what i want to do. Which movement behaviour would you use for that and which specific event do you mean? just want to make sure i am using the right thing for my tests thanks.AJTilley2012-05-05 20:38:04
B
25
S
7
G
5
Posts: 185
Reputation: 5,056

Post » Sun May 06, 2012 6:31 am

It will work with Platform behaviour, using the Set Vector Y event. For checking the vertical speed you'll need to use an expression like Player.Platform.VectorY, as there isn't a condition for checking the individual X and Y speeds.
So like this:

Just swap out Space with whatever you want as input (in your case, probably the mouse), swap Player with whatever object you have that needs the variable jumping, and tune the numbers a little to see what looks best.
Hope this helps you.PixelMonkey2012-05-06 06:33:02
B
62
S
26
G
12
Posts: 122
Reputation: 11,330

Post » Sun May 06, 2012 8:50 am

Thanks again pixel monkey, I did a lot of playing around with those variables and managed to get what I needed the game to do, thank you. :)AJTilley2012-05-06 08:51:05
B
25
S
7
G
5
Posts: 185
Reputation: 5,056

Post » Wed Aug 08, 2012 5:29 pm

Just tried to pull this off myself. It's nearly there but can you clarify how to put that system expression in PM? I must just be missing something but I can't find any system field to put that expression in.

Thanks in advance!
B
20
S
3
G
4
Posts: 77
Reputation: 3,346

Next

Return to How do I....?

Who is online

Users browsing this forum: R0J0hound and 20 guests