• News

• Industries

• Learning & Support

• Community

• Marketplace

# Mechwarrior Style Acceleration

Hi all. I’ve been trying to implement Mechwarrior style movement. I’m currently trying to get the acceleration, deceleration / reverse working.

Holding W will increase the acceleration to 100%. Letting go of W will leave the mech movement at whatever % you ended up on. Holding the W key more will further increase the %

Holding S will do the reverse. If you are at 100% forward movement, holding S will decrease the % until it reaches 0, then eventually -100%. Making the mech reverse.

This is where I’m at currently.

So each mech will be able to accelerate to +/- 100% in forward and reverse. Then each mech derived from this base class will have a maximum speed, which is multiplied by the throttle amount.

Currently, the mech stops as soon as you let go of W. It should continue at its set speed.

So I need a variable to store the current throttle%? So when the W key is released it sets it to that value.
I also need some way of controlling how long it takes to get to 100%.

Setting the throttle to 100% and actually reaching the max speed will also be different. It will take approx 3 seconds of holding the W to get to 100% throttle. But it will take longer to reach the mechs max speed.

Can anyone give me some tips on how to achieve this sort of thing?

Much appreciated everyone. Thanks in advance!

I’m working on a similar concept but in a different context.

Here’s how I did it:

You need to track a couple more values to get the desired effect:

1. ThrottleLevel (clamped between -1.0 and 1.0)
2. EnginePower
3. MaxEnginePower (This you would be able to define on each child class that inherits from your parent)

On Input W use the FInterp to Constant node to increase the throttle toward 100% (1.0)
Multiply the ThrottleLevel by the **MaxEnginePower **to give you your EnginePower
Move actor using EnginePower as your scale value

On Input S use the FInterp to Constant node to decreasethe throttle toward -100% (-1.0)
Multiply the ThrottleLevel by the **MaxEnginePower **to give you your EnginePower
Move actor using EnginePower as your scale value

Hi Thorax,

I’m sorry for that slack experience

The easiest way to build this is by using AxisInput instead of ActionInput. Axis Input works both with joysticks and keyboard and is updated on every frame, which means you don’t have to bother with keys being pressed/unpressed events.

1. bind new AxisInput event in ProjectSetings->Input
2. assign both W and S to it with -1 multiplication for S
3. add this AxisInput event to the event graph
4. the output variable of this event, on every tick, will provide a value between -1 and 1 depending if W or S are pressed or not. Let’s call it axis input ( not sure if it’s called like this)
5. To get the math right and independent from fps, we need to use GetDeltaSeconds node
6. then the math is like this:
Throttle = throttle + axis input * ratio * GetDeltaSeconds
Ratio should be a small number and controls how fast throttle will change.
The only thing left to do is to clamp throttle value to some limited range like -1 to 1 using Clamp node.
So full expression will be
Throttle = clamp( throttle + axis input * ratio * GetDeltaSeconds, -1, 1)

Thanks for the help BoredEngineer. And no worries. I’m sure he meant well.

Anyway, this is what I have so far. Ive clearly done something horribly wrong.
https://imgur.com/8wf866a

The value of Acceleration Ratio is currently 100.
As soon as I hit play the player is moving forward. The printstring reads 0.208338.
Upon pressing w, it instantly jumps to 1.041692, and S it goes to 0.625015.

I tried clamping the end if the equation. Same thing, except forward is alway 0.25 then 0.833353 when w is held and doesnt change when I press s.

Any ideas what I’m doing wrong?

Thanks again. Very much appreciate any pointers!

Hey!

You basicly create 4 different variables: Current Speed, Max Speed, Ratio and Inertia percentage. The rest is shown on the picture :).

• The Ratio is how fast you can accelerate/decelerate.
• The Current Speed is self explanatory.
• Max Speed is self explanatory.
• Inertia percentage is the overall percentage between current speed in relation to max speed.

NOTE: I used the third person blueprint as the test object.

That won’t work.
Throttle = Throttle + …
means that you have to set result of calculations into Throttle variable first, as DarkGodsLair does with CurrentSpeed. Only after that you use it in calculation of “speed” or provide as input into AddMovementInput.

Thank you all very much.

So ive got it set up like this now.

Ive set the clamp before the throttle percent to 100+/- because when its set to just 1, you reach it almost instantly.

Im not sure the math is 100% yet but its certainly better than ive been able to achieve so far.

What im noticing is that I can hold w and the current speed value will keep going up and up until it reaches the max walk speed. Even though I long passed the max throttle percent of 100. Not sure if im just not reporting the currentspeed value correctly to print string.

Its kind of hard to tell if the current speed is properly tied to the throttle percent.

Setting the acceleration ratio works perfectly.

All in all its working very well. Best part is it all makes sense.

I really do appreciate the help. This is the best way for me to learn this sort stuff.

I just need a way to report an accurate current speed. And how max walking speed equates to kph.

For example, the standard walking speed is 600. Would that be 600 units per some amount of time?

Thanks again all. Youve no idea how much I appreciate the help!

Sonething else I’ve noticed that I thought would be a quick fix.
The clamp before the throttle percent isnt working as intended. If for example I hold w after its reached 100 for a few seconds, I have to hold down s for a few seconds before it starts to decrease again.

I thought that if I set the throttle variable min and max value range in the details panel that it woukd solve the issue, but it doesn’t seem to.

Thanks again everyone.

I have to apologize. I ran different values and I am getting the same result. I think I screwed up my percent formula somehow.

EDIT: I am a dummy. My formula was reversed :). You just need to update this part:

The thing you experienced was caused by the wrong formula I used in the first blueprint. We clamped the percentage of the acceleration to not exceed 100%.

Now a little example:

Max Speed: 300
Current Speed: 200

First Formula result: (300 * 200) / 100 = 600% (That is completely off).

We clamped the percentage to 100%. So if we want to go below 100% again at the current speed, we would need to subtract 500% first, creating this issue you dealt with.

Now I corrected the formula and this is my result, when I calculate my example:

Updated Formula result: (200 / 300) * 100 = 66, 67%. This makes much more sense :).

EDIT 2: I calculated roughly, what the movement speed relates to in real world measurements. Keep in mind that this is not 100% accurate, because I rounded values.

• I first ran a test to see, how long it takes a character to traverse 10 cubes. One standard cube of Unreal is 1m * 1m * 1m. So I had 10 cubes (10 meters in Unreal).
• I set the character to have a max walk speed of 100 and set the acceleration absurdly high to get a constant value. To give the walk speed some kind of measurement, I called it MU (Movement Unit). So I am using 100 MU.

Real world measurement of 1 km/h or 1 kps = ~0, 28 m/s

Example:

100 MU

Measured time for traversing 10 cubes (each 1 m): ~10,8 seconds.

Recalculation to meters per seconds: 10,8 seconds / 10 m = ~1,08 m/s.

Conversion from measurements in Unreal to real world measurements: 1,08 m/s / 0,28 m/s = ~ 3,86 km/h

100 MU = ~ 3,86 km/h or kps

1 MU = 3,86 kps / 100 = 0,039 kps.

So in terms of your question, a movement speed of 600 MU would be: 0,039 kps * 600 MU = 23,4 kps.

I hope this helps somehow :).

Sorry for the delay, been super busy.

Awesome. I do appreciate the help.

I will check out the math at some point for getting accurate real world values in game. (I’m wondering if the vehicle starter shows accurate real world scale speed values in kph)

This is where I’m at now.

Unfortunately however. The speed doesn’t seem to be varying at all. It’s either full speed or reverse full speed.

Also. When reversing, the clamp doesn’t seem to be working 100%.
It needs to be a variable so I can set the percentage of the max speed that each mech can do in reverse.
So some mechs will only be able to reverse 30% of their max forward speed, some 40% and so on.

Whats happening is it continues past 25% even though its clamped to 25%. The value only goes to 25%, but if you hold reverse after 25%, there is a delay when trying to go forward again. Before it goes from -25% back to zero.

I haven’t sussed that one out. Few other things ive added and whatever but I just can’t get this to work properly.

Is it a good idea to base the class on character? Or would I be better off using Pawn? Then avoiding using the character movement component?

Im currently not using it for much.
The mech wont be able to swim, crouch, jump. Is it beneficial to use the character class over pawn?

Thanks again all! Much appreciated!

I can’t seem to open the attachment.

To the other thing: I would recommend using the character base class. If you use the pawn class, you would need to create a movement system yourself and a special AI system on top of that (except you want to use the AI systems community members made and revamp them to your suits).

This is by no means a path you need to choose though. Having control over the pawn class can have it’s benefits too :).

Apologies. Don’t know what happened with the screenshot. Fixed it anyway.

And in that case, I will stick to using the character class as a base.

Thanks again!