# Variable height jump with physics?

Get help using Construct 2

### » Wed Dec 28, 2011 7:33 pm

Just a quick question.
I am using physics to make a platformer game. However I am not sure how to accomplish variable height jumps with physics (as in a long press means you jump higher than a short tap).
Basically it should work like this.
As you press space you apply an 'impulse' and immediately start ascending and decelerating. However whenever space is released, the vertical velocity needs to completely stop (i.e. advancing the deceleration).
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,739

### » Wed Dec 28, 2011 8:13 pm

maybe while space is pressed add force a couple of seconds? , if you stop vertical velocity, it will stop moving abruptly, you should let the gravity control thisvtrix2011-12-28 20:14:02
B
72
S
22
G
7
Posts: 830
Reputation: 10,214

### » Wed Dec 28, 2011 11:49 pm

I think you can use the same trick as what I use with the platform behavior

set a JumpCap instance variable (the value should be tweaked by trial and error)

and in event

[code]Keyboard: [invert] Space is down
LocalYVelocity < JumpCap
-> set LocalYVelocity to JumpCap[/code]
Of course, you will have to calculate this LocalYVelocity which is a projection of the world-space velocity to the player object-space (or player-space).
And then you will have to convert the set LocalYVelocity back to world-space :D (lots of fun isn'it?)

Well if you look at the last capx I cooked for you you might find some ways

By the way, it's < JumpCap and JumpCap should be negative. It's the Vertical velocity you want your player to have if you release space and you're still under its value (which means you're still going up in player space). You don't cap to 0 to avoid too sharp transition but to a low negative value.Yann2011-12-28 23:52:03
B
69
S
22
G
14
Posts: 1,488
Reputation: 16,594

### » Sun Mar 11, 2012 12:28 pm

Been trying to get this behaviour working as well. Any chance I could get to take a look at the capx?
B
6
S
1
Posts: 46
Reputation: 856

### » Sun Mar 11, 2012 12:41 pm

I think the easiest way to do this is use impulse and every time you hit a key, eg. space, apply the impulse to your characterWeishaupt2012-03-11 12:41:37
B
44
S
24
G
13
Posts: 723
Reputation: 15,095

### » Sun Mar 11, 2012 1:00 pm

Yes, Construct 2 is missing "Jumping Peak", what is common in my other game makers.
B
109
S
24
G
18
Posts: 1,388
Reputation: 22,956

### » Sun Mar 11, 2012 1:10 pm

I think the way yann is describing it is the way I'd like to use it. just not exactly sure how to implement it at this stage. I sort of understand how to do it and will have fiddle around with it a bit later but I suspect my way of doing it wouldn't work so that's why I'm asking if he could share the capx with the rest of the community. :)
B
6
S
1
Posts: 46
Reputation: 856

### » Sun Mar 11, 2012 1:55 pm

Well I did it by changing the behavior of the character from Physics to Platform.

Then, whenever space is released, and vectorY < 0, set vectorY to vectorY / 2.
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,739

### » Sun Mar 11, 2012 6:03 pm

That worked wonders. Thanks for sharing. :)
B
6
S
1
Posts: 46
Reputation: 856

### » Sun Mar 11, 2012 10:52 pm

No problem ;)
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,739

Next

### Who is online

Users browsing this forum: No registered users and 15 guests