playMaker

Author Topic: Making a smooth speedup and slowdown magnet [SOLVED]  (Read 2636 times)

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Making a smooth speedup and slowdown magnet [SOLVED]
« on: August 03, 2016, 03:13:33 AM »
Hello guys,

i am making a small shmup with the ship having a magnet for pulling credits that stay behind destroyed enemies.

The first part was quite easy:

1. I put the Get Distance action and i store the distance from the object that will be attracted to the Player in the Distance variable.
2. In the Conditional Expression, if the Distance variable is under predetermined value, we go to the next state.
3. Move Towards action is targeted towards Player, with the Max Speed set as MaxSpeed variable.
4. In the Fload Add action i set the Float Variable to MaxSpeed, set the desired increment in the Add field, check every frame, and the magnet is working.
5. To stop the magnet from working, i insert Get Distance action and Conditional Expression again to revert to state one when the object gets out of the magnet's "range". Unfortunately, it stops immediately. So i inserted the third state with Ease Float that will revert to the first state on finish event, but i'm not sure how to set it up, i'm using MaxSpeed as From Value, To Value is 0, but it stops immediately also. I also tried to use Get Speed 2D action, store it in Speed variable and put it in From Value, but it's not working. Any ideas?
« Last Edit: August 04, 2016, 08:32:29 AM by krmko »
Available for Playmaker work

kavery

  • Full Member
  • ***
  • Posts: 149
Re: Making a smooth speedup and slowdown magnet
« Reply #1 on: August 03, 2016, 09:16:03 AM »
I've had trouble using ease float. You could try Float Interpolate, or Lerp? Or maybe an Itween Move To with an ease out.
« Last Edit: August 03, 2016, 09:26:09 AM by kavery »

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Making a smooth speedup and slowdown magnet
« Reply #2 on: August 03, 2016, 09:56:58 AM »
Can't figure out the float interpolate either. Doesn't work with MaxSpeed variable, don't know why. And i don't quite get it why does it need a value to be stored?
Available for Playmaker work

kavery

  • Full Member
  • ***
  • Posts: 149
Re: Making a smooth speedup and slowdown magnet
« Reply #3 on: August 03, 2016, 10:20:27 AM »
If you aren't sure why it gets stored, maybe you are thinking about it wrong. It should store the interpolated value in realtime. You then use that changed value as the new value.

So if you have a max speed float, and then interpolate it to 0 over a period of time, you will create a new float variable (stored) from that calculation. It won't just modify and update the original float. When getting the new stored value, make sure it's on every frame.

To help understand, make sure you open your PM editor and view the variables during runtime. This will help you see what's happening. You should see the stored float changing numbers.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Making a smooth speedup and slowdown magnet
« Reply #4 on: August 03, 2016, 12:11:34 PM »
Oh, i was thinking that it changes the value of the variable to the interpolated value, but instead i have to create a new variable and apply it via new action. I'll check it out and let you know how it works :)
Available for Playmaker work

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Making a smooth speedup and slowdown magnet
« Reply #5 on: August 03, 2016, 05:02:04 PM »
Ah, i knew this wouldn't pass without problems. Everything works fine when the object to be pulled is in the scene, but when i make a prefab, it doesn't seem to work.

Of course, since it is a prefab the conception is a bit different, first step is find the player object and store it, the rest is similar, but when i start, find object action is greyed out, and not working, why?

« Last Edit: August 03, 2016, 05:05:48 PM by krmko »
Available for Playmaker work

kavery

  • Full Member
  • ***
  • Posts: 149
Re: Making a smooth speedup and slowdown magnet
« Reply #6 on: August 03, 2016, 05:23:59 PM »
I'm not sure what your larger problem is, but I think the grey means the action was completed. Whether or not it did what you wanted I'm not sure. The others are not grey because they happen on every frame.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Making a smooth speedup and slowdown magnet
« Reply #7 on: August 03, 2016, 05:36:41 PM »
Thank you, i wasn't aware that grayedout means complete  :-[

Larger problem is that  the conditional expression never gets fulfilled, fsm never moves to state two, strange.

Edit: The distance was a problem, somehow, while on the same z axis, when overlapping, the objects had a distance of 3, while magnet was activated at distance of 1.

Anyway, mission complete, thanks kavery!

« Last Edit: August 04, 2016, 03:54:52 AM by krmko »
Available for Playmaker work

kavery

  • Full Member
  • ***
  • Posts: 149
Re: Making a smooth speedup and slowdown magnet
« Reply #8 on: August 03, 2016, 07:41:26 PM »
I still learn little things like that everyday.

You could try a float compare action instead.