playMaker

Author Topic: Change Gravity to Zero if transform.position Y => a certain value.[SOLVED]  (Read 965 times)

curb47

  • Sr. Member
  • ****
  • Posts: 256
Hi everyone, I hope you're well.

I've got a little conundrum. I have a little spaceship, sideways scroller shoot 'em up type thing, and I want to make it so that when it goes high up, to a certain Y position value, gravity changes to 0.

I've got something that looks like it's going the the right direction, I just need a bit of help.

On the rigidbody for the spaceship I have un-ticked the 'Use Gravity' box, and put an 'Add Force' action on the ship's FSM, set at -10 on the Y (every frame) to simulate gravity.

I have also added a 'Get Position' action onto the ship, and set a variable (height) on the Y value.

Basically, I want something like - If transform.position Y>= 40, then Add Force Y ==0.

Essentially, I'm trying to simulate the little spaceship breaking the gravitational pull of the 'planet', and floating in zero-G space.

I'm struggling to figure out the 'If' 'Then' kind of structure in Playmaker.

Any help is greatly appreciated.

Thanks,

James.
« Last Edit: June 25, 2020, 01:46:47 PM by djaydino »

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Change Gravity to Zero if transform.position Y => a certain value.
« Reply #1 on: June 25, 2020, 11:57:39 AM »
Mmm. Surprisingly, I've actually managed to do it!

Sweet!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

 Cool :) can you share some infos on how you achieved it?

Bye,

 Jean

curb47

  • Sr. Member
  • ****
  • Posts: 256
It was actually really easy, just using a Float Compare. On the main State that controls the Spaceship, I just set the downward force to -10 (to simulate gravity, as mentioned above).
Using the Get Position of the ship, it was just a case of comparing the Y position to a set float (height of transition to zero-G), so if Y>= 500 (for example) then move to a 'zero-G control' state.

The 'zero-G control' state is just a duplication of the first control state, but with the downward force removed. Then, in this state, I've done an inverse of the float compare for when the ship re-enters the gravity pull, and it switches back to the first control state.