Hello,big fan since SoftEngine. However, my racers crash into each other at the very first corner, any idea how we can avoid that? They do in both versions, 2d and 3d
Viewing post in Simple Racing Engine (3D + 2D) comments
Oh wow, that's a blast from the past!
The big issue here probably is that all racers try to follow the center of the racetrack exactly, especially if they all have the same speed and turning values that also means they try to take the same turn. There's a bunch of ways you could adjust csc_ai to fix this...
- Give each AI new variables for angle tolerances instead of using hardcoded 45, 90 and 5 degrees as breakpoints, these should be set using random_range() in the create event of obj_car and then used in csc_ai.
- Another idea is to add a random coordinate (x,y pair) which is added to the target position (when setting tgdir) so the car doesn't try to move towards the same point all the time, you'd set them to 0 in the car's create event and then re-randomize them occasionally using an alarm.
- You could also adapt csc_ai to check for nearby cars ahead of you (using the regular Game Maker collision functions) and try to avoid them by adding/subtracting from tgdir depending on the angle/distance to the car ahead. I don't have a quick fix idea for how to do this but a simple starting point would be to raycast a couple of times (using collision_line), starting at 0 degrees relative to the current facing angle and gradually moving outwards, and then add a value in the other direction to the desired movement angle if there's a car in the way.