playMaker

Author Topic: Calculating Speed Per Second/Distance[SOLVED]  (Read 824 times)

Gignormaz

  • Playmaker Newbie
  • *
  • Posts: 8
Calculating Speed Per Second/Distance[SOLVED]
« on: May 08, 2020, 08:15:09 AM »
Hello guys!

First time poster here.
I've moved over from unreal engine and have begun my adventures on Unity and playmaker. I've finished a few tutorial courses and have begun work on a new creation, however I'm a little stuck.

I've got a button that adds X to a "speed" counter. I then want it to subtract it's worth from a "distance" slider. What would be the best way to do this?

This button also is to be clicked and hit a ceiling with the speed falling back down to zero unless it keeps getting pressed. I"m guessing i'll need some custom actions for this.

I suppose an example would be hammering home the button reduces the distance to the checkpoint, not pressing it brings it back down over time. Like an orange mushroom to the finish!

Sorry if my explanation isn't very good, it's hard to describe!

Thanks in advance for any help

G
« Last Edit: May 13, 2020, 01:39:52 AM by jeanfabre »

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Calculating Speed Per Second/Distance
« Reply #1 on: May 08, 2020, 09:33:14 AM »
Welcome!

This sounds like it can be build with standard actions, depends on what exactly a distance slider is and so on. It seems you need two FSMs. One that houses the Distance value that gets constantly decreased, and one that watches an input and which adds again.

As a recommendation, separate mechanics from visuals and even the input at first. So to get it going, make one state that listens for a GetKeyDown. Just “hardcode” any for now. Later, you can trigger it with an UI element etc.

To decrease, you need two states. First one a Wait, and the second with Float Subtract or Float Operator etc. and returning to first after Finished. Finished is an event that is internally raised when all actions in the state are done. As as an transition below the state will leave the state. So the variable in the Wait is your tick, how often or quickly it is reduced. Be sure to set it in the variable tab.

When this works, you need to account for adding. A simple way could be to add another Float Add action, and a myVar variable . It must be zero by default and you reset it to zero every tick. When returning to the first state, above the Wait, add a Set Float value for myVar and set it to zero. That means, every tick, it‘s set back to zero. This alone will just decrease your distance value, since myVar right now is always zero. But you want to Clamp the distance value etc first. Observe how the decrease works.

Then add a second FSM, which listens to a key and adds. To do this, make one state to listen for a key with GetKeyDown (it’s ok for prototyping or simple games, but later replace with proper input scheme). After the key was pressed, go to a second state, and here we Send FSM Float to the first FSM, setting its myVar to a positive value.

That means, the first FSM will be adding it and then when returning to the wait tick, empties out the myVar float again, until the player presses again.

You can switch debug on in the variable tab and observe the numbers. If that’s all good enough for now, you make a third FSM that can e.g. read the values with Get FSM float and update sliders etc. (you can also send a global event like Update UI and the UI element listens to this and updates accordingly)

Hope that gets you started.


« Last Edit: May 08, 2020, 09:44:51 AM by Thore »

Gignormaz

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Calculating Speed Per Second/Distance
« Reply #2 on: May 12, 2020, 07:18:45 AM »
Sorry for the late reply!

I just wanted to say a huge thank you for spending the time to answer me.

I've managed to get what I needed to up and running and it feels good to see it coming together! That was a well detailed reply and I've managed to use it to create some more complex actions. I really appreciate people taking the time to help out beginners on forums like these as it's all too easy to ignore.