Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

It happens instantly only when pointing in the direction of the track. Take a close look at the demo, it also happens in there but is not easy to notice. If you enlarge the track you will see it well.

Your questions:

  • I'm using GMS2
  • No big changes. Only the way the "accel" variable is modified when pressing the up key to make it non linear (I'm trying to recreate an engine power curve). No changes were made to the d3d logics.
  • This effect happens when the car is stopped or under certain velocity, it just stops moving forward but keeps moving to both sides depending on direction. I've tried this with the source code unchanged with a larger track. 

Thanks, managed to get a 100% reproduction method working now... angle slightly, stand still, then tap 'accelerate'. I'll see i I can figure out what causes it.

I think I've figured out what's happening, but not WHY... the U position (how far you're along the track) seems to only update in increments of a set size, so at small speeds it get snapped back after updating. The W position (sidewaysness) isn't affected by this, so you can move sideways just fine.

Okay, I think I've figured it out! It's GM's float numbers being too imprecise, essentially. I added a bit of a hack to make the track position bigger to have more decimals around, and that solved the problem.


Here's the changes you need to do:

  • In obj_trackcontrol's create event, below the line that sets "global.ufactor", add something like global.uufactor     = 1000/global.tracklength
  • When trackcontrol creates cars, below the line "n.u = u", add the line n.uu= n.u*1000
  • In player_apply_movement, remove the line that sets u and replace it with the following two lines:
    • uu         += lengthdir_x(argument1*global.uufactor,alpha)
      u = uu/1000

You could substitute the 1000 for any number you want, I'll do that with a macro and then export an updated version of the engine file.

Fixed version is uploaded! It's just a change of like 3 lines, so it might be easier to just manually apply the git diff to your existing project:

diff --git a/SimpleRacingEngine_3D_carmodels.gmx/SimpleRacingEngine_3D_carmodels.project.gmx b/SimpleRacingEngine_3D_carmodels.gmx/SimpleRacingEngine_3D_carmodels.project.gmx
index 622e83f..59e20a7 100644
--- a/SimpleRacingEngine_3D_carmodels.gmx/SimpleRacingEngine_3D_carmodels.project.gmx
+++ b/SimpleRacingEngine_3D_carmodels.gmx/SimpleRacingEngine_3D_carmodels.project.gmx
@@ -105 +105 @@
-  <constants number="8">
+  <constants number="9">
@@ -108,0 +109 @@
+    <constant name="TRACK_U_PRECISION">10000</constant>
diff --git a/SimpleRacingEngine_3D_carmodels.gmx/objects/obj_car.object.gmx b/SimpleRacingEngine_3D_carmodels.gmx/objects/obj_car.object.gmx
index 3073c84..0d4bd06 100644
--- a/SimpleRacingEngine_3D_carmodels.gmx/objects/obj_car.object.gmx
+++ b/SimpleRacingEngine_3D_carmodels.gmx/objects/obj_car.object.gmx
@@ -36,0 +37 @@ u = 1.00//Forward coordinate
+uu = TRACK_U_PRECISION
diff --git a/SimpleRacingEngine_3D_carmodels.gmx/objects/obj_trackcontrol.object.gmx b/SimpleRacingEngine_3D_carmodels.gmx/objects/obj_trackcontrol.object.gmx
index c55c5c8..c8882e3 100644
--- a/SimpleRacingEngine_3D_carmodels.gmx/objects/obj_trackcontrol.object.gmx
+++ b/SimpleRacingEngine_3D_carmodels.gmx/objects/obj_trackcontrol.object.gmx
@@ -73 +73,2 @@ global.ufactor      = 1/global.tracklength
+global.uufactor     = TRACK_U_PRECISION/global.tracklength
@@ -105,0 +107 @@ for(car = 0; car < global.cars_total; car++){
+    n.uu= n.u*TRACK_U_PRECISION
diff --git a/SimpleRacingEngine_3D_carmodels.gmx/scripts/player_apply_movement.gml b/SimpleRacingEngine_3D_carmodels.gmx/scripts/player_apply_movement.gml
index 3e6cf06..3f204c1 100644
--- a/SimpleRacingEngine_3D_carmodels.gmx/scripts/player_apply_movement.gml
+++ b/SimpleRacingEngine_3D_carmodels.gmx/scripts/player_apply_movement.gml
@@ -16 +16,2 @@ alpha       = angle_difference(trackdir,argument0)
-u          += lengthdir_x(argument1*global.ufactor,alpha)
+uu         += lengthdir_x(argument1*global.uufactor,alpha)
+u = uu/TRACK_U_PRECISION

Perfect!! It works like a charm now! Thanks Yal!! 

I must ask for something else if you don't mind: can you upload some documentation  about how to import 3d models into the engine? I mean, if that is possible. If don't, a tutorial explaining how to create them from paths, how to apply some textures and set the proper collision mask.

Thanks again, Yal!! You've made a wonderful job here!!

The models all are created from paths, I have no experience with "proper" 3D modelling (Blender etc) so I wouldn't really know how to import new ones.

  • Path0, 1 and 2 respectively are the silhouette of the car at the center, a bit outside the center, and at the left/right sides.
  • PxLengthFactor is the downscaling factor from path coordinates to model coordinates (the paths are pretty big thanks to how the grid is defaulted).
  • W0, W1, W2 and W3 are how far left/right from the center the paths are placed when used as a guide for the model. These are raw model coordinates, they don't use the PxLengthFactor. So for instance having a higher W0 means the cockpit is wider, having a W3 much higher than W2 makes the car have bigger wings, and so on.
  • W3 must always be greater than W2, W2 greater than W1, and so on. (You don't NEED them to be greater, but the model will clip into itself if not).
  • The texture is mapped like this: every horizontal 25% of the texture is used for the section between two W*s. So the first 25% of the texture are used for the section between -W0 and +W0, the next 25% are used for the section between W0 and W1 on both sides, and so on. It's stretched evenly from the front of the vehicle to the back (the top of the texture maps to the start of the path, the bottom to the end of the path)
  • Currently the model doesn't affect the collision mask at all, the cars all use the car sprite as a mask. You could extract the car's length from the modelling script by storing the "xx" variable of the first and last iteration (first iteration's lower value + last iteration's higher value, it's an array) and the W3 (outermost width)... those will give you the bounds of the car's model's bounding box, and then if you used an ellipsoid collision you'd get an okayish result. Probably would be the easiest to make a circle-shaped sprite for collision masks (with Ellipse collision mask settings, sprites default to "rectangle") and then scale image_xscale / image_yscale based on the bounding box size so the sprite covers the same region (e.g. if W3 is 8 and the sprite is 32x32, image_yscale should be 0.5 because (8*2)/32 = 0.5)

Hope this helps :)

(+1)

Thank you!!