playMaker

Author Topic: Jump in 2D Platformer  (Read 4449 times)

krimson0

  • Playmaker Newbie
  • *
  • Posts: 10
Jump in 2D Platformer
« on: June 19, 2013, 09:29:34 PM »
Hi,

I just started using playMaker and am pretty new to programming in general. I'm playing around with trying to make a 2D platformer type control.

I've looked at this tutorial
Not a valid vimeo URLvideo/21880268
I like how it's set up so I'm trying to replicate it using playMaker. The first attatchment(inputState01.jpg) shows what I have so far. Everything works fine, except when it comes to the jump.

In the tutorial, the jump seems to reach the jumpSpeed height and falls down. However, in my case, the jump keeps going as long as the space bar is held. This makes sense why it happens but I guess I don't get why the tutorial one works the way it does, or how I would translate that to playMaker.

The concept is also based off of an answer to this thread
http://hutonggames.com/playmakerforum/index.php?topic=3516.msg16182#msg16182
by user greg. So I would like to know how to get it to work properly.

Furthermore, eventually, I would like to split the actions of the state into an fsm that looks like the second image(fsm01.jpg). I would like this so I can keep different status of the character in different states to provide flexibility in each status. If this is not good than feel free to advise. The jump however also doesn't work for this. After jump is initiated, it jumps to "in air" and keeps going up. When I try to re-define gravity in "in air", the player starts falling immediately after jumping.

Any help/suggestions/critiques would be great since, again, I am rather new to all this. Thanks for your time.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Jump in 2D Platformer
« Reply #1 on: June 20, 2013, 01:35:58 AM »
Hi,

 your likely problem is the following: they only apply a jump speed once, when the user press the jump button, NOT every frame that the user has pressed.

 you should use "Get Button Down" action and not "Get Button".

try this, I think this will solve your issue.


splitting behavior in Fsm make sense in many cases, especially when you want to have concurrent behavior. Since there can be only one state active, sometimes you must plit your logic into several fsm, so don't worry this is common,


bye,

 Jean

krimson0

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Jump in 2D Platformer
« Reply #2 on: June 20, 2013, 09:49:00 PM »
Hi Jean,

Thanks for the reply. The Get Button Down does solve the holding space down and floating issue, however, the jump is still very sudden and gets dragged down real fast. It is similar to my second version where I have an in air state that does not have the get button.

Looking at the tutorial example, I notice that the moveDirection.y value climbs toward the goal value rather than changing into it. I have a feeling this is why the jump and fall is gradual. Also, this give a acceleration for gravity that feels more natural. To simulate the effect, I have added a subtract float per frame per second, to emulate moveDirection.y -= gravity * Time.deltaTime. Since there is no subtract vector3.y or similar action, I had to create another float. The result does makes the moveDirection.y value slowly climb toward gravity value. Very similar to how the script works. However the value keeps going, the action keeps repeating. While in the script, it caps at 20 and resets when it hits the ground.

Sorry for all the questions, again this is all pretty new. I guess I'm not fully grasping the logic of the script and why it's not creating the same issues as my fsm. Seems var are getting reset somehow. Thanks for your reply though.

krimson0

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Jump in 2D Platformer
« Reply #3 on: June 20, 2013, 10:25:02 PM »
Sorry seems like the script, gravity will keep making the moveDirection.y keep falling in value as well. So I guess the problem now is just the jump still. It still just snaps to the value rather than climb toward it and stop.

krimson0

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Jump in 2D Platformer
« Reply #4 on: June 20, 2013, 11:58:25 PM »
To clarify, was able to reset the moveDirection.y from climbing by reseting it everytime controller is grounded is true. That way it matches the example.