playMaker

Author Topic: Character is jumping indefinitely  (Read 1235 times)

luc97

  • Playmaker Newbie
  • *
  • Posts: 4
Character is jumping indefinitely
« on: June 13, 2020, 08:34:40 AM »
Hi its me again  ;)
Sorted jumping but now my character is jumping without limits I can go up in the air much as I want... any ideas?

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Character is jumping indefinitely
« Reply #1 on: June 13, 2020, 09:28:10 AM »
State 1: listen to input (keys, buttons etc), if pressed...
State 2: AddForce(2D) set to impulse, once, end the state, back to State 1.

Next, you want to add a state in between to check for conditions, like is the character grounded etc.

luc97

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Character is jumping indefinitely
« Reply #2 on: June 13, 2020, 09:44:26 AM »
State 1: listen to input (keys, buttons etc), if pressed...
State 2: AddForce(2D) set to impulse, once, end the state, back to State 1.

Next, you want to add a state in between to check for conditions, like is the character grounded etc.
I have:
State1-get key down (space) Event (jump pressed) and choosed in send event
State2-Add force 2d and here I've put Force mode on Force cause after setting on impuls character is teleporting up o.O and changed "Y" for 320 rest is default and FINISHED so I think I got everything right even done it same as a guy on yt and the character is jumping that many times as I will press space and what do You mean "once"?
« Last Edit: June 13, 2020, 09:46:54 AM by luc97 »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7624
    • jinxtergames
Re: Character is jumping indefinitely
« Reply #3 on: June 14, 2020, 07:18:17 AM »
Hi.
I use a raycast that continues checks for ground (on a different fsm) and sets a bool.

Then on jump fsm do your jump, then use "Fsm Bool Test" (you can find this one on the Ecosystem)
and check if grounded is 'false' (check every frame).
Then you can start check if grounded the same way (in a next state)
and when grounded you can activate jump again.

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Character is jumping indefinitely
« Reply #4 on: June 14, 2020, 09:37:35 AM »
State 1: listen to input (keys, buttons etc), if pressed...
State 2: AddForce(2D) set to impulse, once, end the state, back to State 1.

Next, you want to add a state in between to check for conditions, like is the character grounded etc.
I have:
State1-get key down (space) Event (jump pressed) and choosed in send event
State2-Add force 2d and here I've put Force mode on Force cause after setting on impuls character is teleporting up o.O and changed "Y" for 320 rest is default and FINISHED so I think I got everything right even done it same as a guy on yt and the character is jumping that many times as I will press space and what do You mean "once"?

First, make sure you use the correct actions. Physics actions, colliders, rays, forces and all of this have a standard version and a 2D version. Pick a suite, but you must use the components and actions consistently then, including PlayMaker actions. So, if your rigidbody is 2D, you must use AddForce2D. PlayMaker should warn you about that.

Next, use force impulse because you want to apply the whole jump force at once in that frame. Once means, that nothing in the jump state (state 2) is set to every frame. I.e. you pass through the state and return instantly to the first state, to jump again.

Tick the "show in inspector" variable on the jump force (which is set into Addforce impulse), and then, while playing, you can change it around and tweak it in the inspector, or in the first tab in the PlayMaker.

Your character will now jump ONCE when you press the key, but you can jump in mid-air. To prevent this, you need to add what DjayDino wrote. This goes into a new state betweem pressing button and adding jump force. I recommend to put the ray for the ground check to a different fsm, because you will have to constantly check anyway, as for when you walk off a platform etc.