Improving the default racing car movement in TGF/MMF

Here is a link to my file that shows this article (TGF .gam format).

First, make an active object for the racing car, and assign it racing car movement. The racecar movement settings do not matter. Just draw it in one direction and then rotate it to all 32 directions, to save time. Go into the event editor and tell it:

-Start of level
.....-Ignore Control (Player 1)
.....-Set Maximum speed to 75
(Your Car object)

This stops TGF from trying to control the car in 2 ways at once.

Acceleration
Make an event:

-Repeat while Shift is pressed (Or any other key you choose for acceleration)
.....-Set speed to Speed(Car) + 1
(Your Car object)

This makes your car accelerate when you hold down the shift button. You could also add a timer event to slow down the acceleration, or a speed limiter event eg. Speed of (Car) < 75 to stop the car from going too fast.

Braking
Make an event:

-Repeat while Control is pressed (Or another key you wish to use as brakes)
+Speed of Car > 0
.....-Set speed to Speed Car - 1
(Your Car object)

This makes your car slow down when you hold control. If you do not have the Speed of car > 0 condition, then the car's speed seems to be -1, making the car move infinitely forward, which can cause TGF to crash, and the world to be nuked by chimera.

Friction
When the player is not holding down the accelerate key (Shift, in this case), friction makes the car slowly slow down.
Make the event:

-(Negate) Repeat while Shift is pressed
+Speed of Car > 0
+Every 00"-05
.....-Set speed to speed(Car) - 1
(Your Car object)

Speed-Based Turning
These events make the car turn when you are holding down the left or right cursor keys, but dependant on speed. When the car is moving slowly, there is a slow timer event that turns the car slowly. It works the same for when the car is moving quickly, there is a fast timer event which turns the car quickly.

Very slow
Very slow turning will turn the car while the speed is very low.
Make an event:

-Repeat while Right arrow is pressed
+Speed of Car > 0
+Speed of Car < 5
+Every 00"-50
.....-Set direction to Dir(Car) - 1

Make another event:

-Repeat while Left arrow is pressed
+Speed of Car > 0
+Speed of Car < 5
+Every 00"-50
.....-Set direction to Dir(Car) + 1

Slow
Slow turning while the speed is low.
Make an event:

-Repeat while Right arrow is pressed
+Speed of Car > 5
+Speed of Car < 20
+Every 00"-25
.....-Set direction to Dir(Car) - 1

Make another event:

-Repeat while Left arrow is pressed
+Speed of Car > 5
+Speed of Car < 20
+Every 00"-25
.....-Set direction to Dir(Car) + 1

Medium
Faster turning while the speed is steady.
Make an event:

-Repeat while Right arrow is pressed
+Speed of Car > 20
+Speed of Car < 40
+Every 00"-10
.....-Set direction to Dir(Car) - 1

Make another event:

-Repeat while Left arrow is pressed
+Speed of Car > 20
+Speed of Car < 40
+Every 00"-10
.....-Set direction to Dir(Car) + 1

Fast
Fast turning while the speed is high.
Make an event:

-Repeat while Right arrow is pressed
+Speed of Car > 40
+Every 00"-05
.....-Set direction to Dir(Car) - 1

Make another event:

-Repeat while Left arrow is pressed
+Speed of Car > 40
+Every 00"-05
.....-Set direction to Dir(Car) + 1


You could add more turning speeds if you want to, but I think that's enough.
I hope you may find this useful!

Return to Phizzy Games - Home.