Reversed Gravity & Jumping

JeffreyDriver

  • Posts: 2262
I've created a script to flip the gravity on a key press but I've run into a problem with jumping. Although the actor can move around on the ceiling,  it can't jump off it like it can on the floor.

Anyone have an idea on how to fix this?

tigerteeth

  • Posts: 733
1. Look at how your jumping behaviour works
2. Create a boolean that shows if gravity is upside down or not
3. Adapt your jumping behaviour in the case that gravity isn't upside down.

It's hard to be more specific without knowing what your jumping behaviour is.

JeffreyDriver

  • Posts: 2262
1. Look at how your jumping behaviour works
2. Create a boolean that shows if gravity is upside down or not
3. Adapt your jumping behaviour in the case that gravity isn't upside down.

It's hard to be more specific without knowing what your jumping behaviour is.

Thanks. I'm really new to Stencyl so I have just used the Jump behaviour which shipped with it. I don't yet fully understand how it functions, so haven't dared to really mess around with it much. I'm at a bit of a loss. I've included a screenshot. Cheers.

tigerteeth

  • Posts: 733
Okay, this might be a bit complicated for a complete beginner (it's probably worth looking at the stencylpedia and the crash courses to learn a little bit about the basic concepts of stencyl) but the changes you need to make are:

1. You need to create a global attribute (boolean type) called "gravityisreverse". Attributes are stored bits of information that we can refer to in code. A Boolean just means a switch with two states (true and false). So you're creating a little way of telling the computer if Gravity is reversed or not.

2. In the code you've created to reverse gravity, it probably says something like "when X key is released, set gravity to ___". Put in another part that says "When X key is released, if gravityisreverse is true, otherwise, set gravityisreverse to false". Do this after you've created your boolean.

3. If you can do all that let me know and then we'll look at your jumping code.

JeffreyDriver

  • Posts: 2262
I think I've managed it! I've attached a screenshot. Thanks.

tigerteeth

  • Posts: 733
Almost! Just a few changes:

Put "set gravityisreverse to true" directly underneath the "if vertical gravity = 85" block and then put another block saying "set gravityisreverse to false" directly underneath the "otherwise" block. Once you've done that, your boolean will return "true" if gravity is at -85, and "false" if gravity is at 85.

After that, you need to change your jump behaviour.

1. Firstly, make a copy of each of the events (when this actor hits something else, always) in your jump behaviour. We're going to make one set of events for when gravityisreverse=true, and another copy (with some changes) for when gravityisreverse=false

2. With the original version of events, put it all inside a wrapper which says "if gravityisreverse = false". That will mean that everything works like normal when gravityisreverse is false, so basically, when gravity is normal, everything is normal.

3. In the copied version of events, you need to firstly put each event (the copied versions of when when this actor hits something else, and always) inside a "if gravityisreverse = true" wrapper. This version of events will only trigger when gravity is reversed. The changes you need to make are:

- In the collision event, change the symbol for "smaller than" to "greater than". Basically, change the > for a <. This makes sure that the collision has been from above (that is to say, the actor has hit the "ceiling") whereas in the original, we were checking if the actor had hit the floor.

- And, in the always event, change the -1 to a 1 in the "push self sharply" block. This changes the direction of the "jump" (-Y value pushes the actor up, positive Y value pushes the actor down).


tigerteeth

  • Posts: 733
Let us know if that solves your problem!

JeffreyDriver

  • Posts: 2262
Quote
Let us know if that solves your problem!

Thanks a lot for your help, but we're not quite there yet I'm afraid! Moving still works whether gravity is reversed or not, but I still can't jump from the ceiling.  I'm guessing I've gone wrong somewhere, but I can't spot where. I've attached a screen shot of the jumping code.

tigerteeth

  • Posts: 733
I'm stumped. Anyone?

TheIndieStation

  • *
  • Posts: 2263
Ill do a tutorial for this tomorow =)

JeffreyDriver

  • Posts: 2262
Well, thank for your help any way, tigerteeth. It is appreciated. I still learnt a couple of useful things, so it wasn't in vain.

TheIndieStation, I look forward to seeing that tutorial! Cheers.

JeffreyDriver

  • Posts: 2262
Okay, so I finally solved this, and the solution was quite simple, though I wouldn't have got there without what I learnt from tigerteeth.

Instead of using a boolean to check the true/false status of my 'gravityisreverse' attribute, I just made it check what the gravity is doing directly e.g 'if vertical gravity = 85'.

The boolean idea should work, but it's not for some reason. At least I've now achieved what I set out to do.

TheIndieStation

  • *
  • Posts: 2263
Sorry for the tutorial delay, but I got carried away when doing the preparations. Now i have a tutorial on how to do 4 way gravity manipulation and movement haha... should be there tomorow!

JeffreyDriver

  • Posts: 2262
Sorry for the tutorial delay, but I got carried away when doing the preparations. Now i have a tutorial on how to do 4 way gravity manipulation and movement haha... should be there tomorow!

I'm still interested in seeing it!