Jump to move 8 directions

Get help using Construct 2

Post » Sun Mar 22, 2015 7:11 pm

Hi everyone, I try to create a game type Street of Rage, but I have no idea how to get a jump when using this type of control (8 direction).

Any ideas? thank you very much
B
27
S
7
Posts: 36
Reputation: 1,604

Post » Mon Mar 23, 2015 9:37 am

Hey @Taximan, :)

One possible approach is, instead of having the 8 direction behavior control your character sprite directly, have it control your character's invisible "footprint" (a separate sprite object). Create a new object to act as your character sprite and, every tick, set its coordinates to match the coordinates of your footprint object.


Altitude variable
Now you just need one more value to store the player's current altitude above the ground. Normally your altitude will be 0, because you'll be standing flat on the ground. When you jump, this value will increase up to your maximum jump height and then decrease back to 0.

So far so good, but that altitude number won't move your player by itself.


Actually jumping
Earlier I said we'd set the character's coordinates to match the footprint's coordinates. We now need to make a small change...

We still make the character's X coord match the footprint's X coord, but we set the character's Y coord to equal the footprint's Y coord PLUS the altitude number.

Now when you move the character should follow the footprint, and when you jump, the character should hop up and down "vertically" over the footprint.
As an added bonus, you can attach a little shadow image to the footprint object and it will always be directly "under" your character even when jumping.


Borrowing Jump altitude from the Platform behavior
Now, if you don't want to build custom code to make the altitude variable "jump" when you press jump, you can borrow the jump behavior from the platform object in a roundabout way.

We basically create an invisible platform object that can only jump, put it somewhere out of the way, and we use its Y position as the real character's jump altitude.

Specifically, we create an invisible platform object with it's controls disabled (so the player can't move it), and then we make the game's Jump key trigger the platform object's "Simulate control" action to simulate a Jump, so the player can make it jump, but not move around.

We'll also need to make an invisible solid object for it to stand on, and we'll position them both so that the platform object's Y coord is 0 when it's resting on the solid ground object.

Every tick, the player's altitude variable should be set to the platform object's Y coord.

This method also allows you to optionally use some of the other nice features of the platform object's jump system, like holding jump to go higher.
B
28
S
18
G
8
Posts: 332
Reputation: 6,191

Post » Tue Mar 24, 2015 1:15 am

Thanks for the reply, my English is very bad, but I understand the idea, thank you very much.

PD. Will comment if I get it.
B
27
S
7
Posts: 36
Reputation: 1,604

Post » Tue Mar 24, 2015 11:07 am

No worries. Hope it works out. :)
B
28
S
18
G
8
Posts: 332
Reputation: 6,191

Post » Tue Mar 24, 2015 11:04 pm

@fisholith - Do you have any thoughts on how you would extend this idea to allow the player to jump onto a crate (and walk around / behind it)?

i attempted it once, but it didnt turn out so great
https://dl.dropboxusercontent.com/u/403 ... index.html
B
88
S
44
G
16
Posts: 1,009
Reputation: 17,971

Post » Wed Mar 25, 2015 4:02 pm

(Note: File and image attaching are not working for me at the moment, so I'm using external URLs for when everything comes back on line.)

Hey @justifun, :)

Essentially you would be simulating a 3D space.
I'll outline some terms and ideas first, and then explain how you might put them together to get your character jumping up onto crates and walking on them.



Three Axes
Ignoring jumping (Z) to start with, you just have X and Y making up the ground plane.

X allows you to walk West and East, which is represented as left and right movement on the screen.
Y allows you to walk North (away from camera) and South (towards camera), which is represented as up and down movement on the screen.

When you add jumping, you now have a third coordinate to keep track of, Z. We track the character's Z coord with our custom altitude variable.

Z allows you to ascend and descent over the "ground", and is represented as up and down movement on the screen.

Since Y and Z are both represented as up and down movement on the screen, in many games a shadow is placed under the character, so that it's easy to tell the difference between walking North and South, and Jumping up and down. When jumping, the character moves up and down, but the shadow stays on the ground at the footprint coords.



Collision & Z-overlap
(image link) - Here the player is in mid jump, and their shadow is visible on the block just below.
Image

If we want the character to be able to stand on a box, then we need to know when the character's XY footprint is overlapping the box's XY footprint.

We also need to know how "tall" the box is, (its Z-height).

Once we know we're overlapping a box on the altitude (Z) axis, we can grab the Z-height value of the box, and use that as the current ground height. If that height is higher than the player's Z elevation, then the box is an obstacle to the player, but if it's lower than the player's Z elevation, then the player can pass "over" the box, or walk on it.

(image link) - Player sitting on a block, overhanging edge. (Player's footprint in green.)
Image

(image link) - Player falling off the block. Notice that the footprint no longer overlaps the block's footprint.
Image

(image link) - Player sitting on ground beside block.
Image



Z-axis physics
In my first post I explained that you could outsource the jumping mechanics to a platform behavior object. In this new case, where the ground can have more than one height things get trickier. It's still possible to outsource to a platform behavior object, but its tricky enough that it might be better to just build your own simple Z-axis physics.



Demo capx
I built a demo capx that shows how some of this stuff could work in practice, though the code is a little hacky in places. :)

fi_demo_JumpingInPseudo3D.capx
Last edited by fisholith on Sat Apr 22, 2017 4:35 am, edited 6 times in total.
B
28
S
18
G
8
Posts: 332
Reputation: 6,191

Post » Wed Apr 01, 2015 1:46 pm

OMG @fisholith - this is exactly what i've been trying to do for ages!!! that you SOOOOO MUCH! you just made my day!
B
88
S
44
G
16
Posts: 1,009
Reputation: 17,971

Post » Wed Apr 01, 2015 1:53 pm

Awesome, glad it helped out. :D
Oh, I fixed the images. My "Img" tags were around the web address, not the file address. Derp. :)
B
28
S
18
G
8
Posts: 332
Reputation: 6,191

Post » Tue Apr 18, 2017 2:45 pm

@fisholith .capx link not working, please reupload it
B
39
S
10
G
5
Posts: 35
Reputation: 4,789

Post » Sat Apr 22, 2017 4:36 am

Thanks for letting me know @redfoc, :)
I just updated the link, so it should work now.
B
28
S
18
G
8
Posts: 332
Reputation: 6,191

Next

Return to How do I....?

Who is online

Users browsing this forum: fellipyextreme and 9 guests