This guide will show you how to control a player’s speed. This is applicable in racing games and games where the player can have lots of speeds.
First, place a lot of speed modifiers. They will go from 1 to 4, in increments of .1. (1, 1.1, 1.2, 1.3, and on and on and on). Make the channel they receive on like this:
"Speed " + Number in the modifier
For the numbers without decimals, do not add the point 0. This format helps us use concatenation to set the speed. Now make a property called “Accel” and “Speed”. They should both be player scoped and numbers.
Make a lifecycle. It should listen for game start and broadcast on “Start Game Start”. Make a relay receiving on “Start Game Start” and broadcasting on “Game Start” to everyone.
To set a default acceleration and speed at the beginning, do this:
Default Speed and Acceleration
Use the defaults on the property if you want a whole number default. If you want a decimal default, continue.
Make a trigger that receives on “Game Start”. In the blocks, set your properties to the defaults.
Make a trigger receive on “Game Start”. Wire this to a wire repeater and back. The trigger should have a delay of .1s. This delay can change. A smaller delay is better, but it has a possibility of lagging out your game, the smaller you go. Now, in the blocks, set the speed property to itself plus the accel property.
Make the “Speed” property broadcast on “Set Speed”. Make a trigger receive on “Set Speed”. Enter this into the blocks:
My multiplication and division look weird because I wanted it to fit on the screen. You can replace the 3 with the highest speed you want. You can replace 1 with the lowest speed you want.
Now, you have something that can control a player’s speed! It’s time for the gas pedal and brake!
Make two overlays, both buttons. One should say Brake and one should say Accelerate. They should broadcast on “Brake” and “Accelerate”. Make two player scoped number properties. One should be called “BrakeFactor” and one should be called “AccelFactor”. In the blocks for the braking overlay, make the block receive on “Brake” and set the acceleration to “BrakeFactor”. Do the same thing for the acceleration overlay but with the acceleration names.
This system makes it so that pressing the button takes you either the top or the bottom limit. If you want more Make a trigger that receives on “Brake”. Wire it to another trigger that receives on “Accelerate”. This trigger should have a delay higher than the delay for the trigger from the start setting the speed to itself plus one. In the blocks for the trigger receiving on “Accelerate”, make it set “Accel” to 0.
You can change the accel factor and brake factor constants in the defaults trigger in the optional section. Now, you just need to calibrate the numbers how you want.
Can someone give some delays and numbers that work pretty well for them?
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10