Looking for a smooth, seamless way to keep a car on the road

SOLVED: I decided to go with just a “corner assist mode” that automatically drives the player around 180 and 90 degree bends, rather than gluing them to middle of the road all the time. And instead of having a cooldown, the player can simply choose to toggle it on or off.

I did this by making a set of 4 navigation meshes, left/right for each turn type, and moving them into position when needed and away when finished. The nav meshes have 3 triggers parented to them: Start Pathing, Stop Pathing, and Move Mesh Home. At every corner, I have placed a trigger that moves the correct nav mesh into place (they also have a parented trigger object that prevents them from firing from the wrong direction).

Doing it this way meant I only needed 4 total nav meshes (and their trigger groups) and by moving them rather than creating/destroying them, I didn’t have to concern myself with object name changes. Also, there are only 4 types of generic triggers to move the nav mesh into place, which means they’ll be really simple to add after I have finished laying out the whole road system. Finally, I chose to use collision and property sensors as triggers, because I figured they would trigger consistently and would be processor efficient (I’ll probably need about 200 corner triggers).

It’s not exactly what I wanted, but I think in the long run it’s probably a better solution, because it still leaves a lot of places where the player has to put some thought and effort into driving lol…

If you want to try it out or see how it was programmed, the project is https://github.com/Tatwi/LoopDipole and the two “shapes” that can use driving assist are enabled by pressing NumPad 5 or 6. NumPad 1 - 4 are gliding/flying type “shapes”. I put a little race track in for testing, so there’s something to drive on.


Howdy fellow Blenderers!

Sorry for posting a question, but I have been working on this issue for months and my research and testing have been unfruitful. I actually don’t like asking for help on projects.

Using the car logic, I have set up an open world driving game, where the player can drive anywhere, on or off the roads. Overall, the game works great, but I am having some trouble creating a “driving assist mode” for when the player is on the roads.

Driving Assist Mode can be toggled on by the user and while it is active, the player is essentially glued to a rail in the center of the road, such that it doesn’t matter how poorly they steer, they will always stay in the center of the road.

What makes this tricky to achieve:

  1. The roads aren’t race tracks, where the player can only go in a single direction. Rather, they are more like real life, with junction points and the ability to travel in either direction.

  2. It’s an open world, where there is stuff do when off the road, so the driving assist needs to be able to start from anywhere the player happens to enter the roadway.

I’ve already programmed tracking when the player is on or off the road and driving assist is enabled while while holding SPACEBAR. The trouble is, I have yet to program a method of driving assist that actually works! lol…

Here are some things I have tried:

  1. Aligning the Y vector of the player to the local Y vector of the ray hit object (road). Works great on a straight line and in a single direction, but is totally useless for going around curves.

  2. Dropping a ray down on either side of the vehicle and pushing the player back into the roadway when the left or right ray stops touching the road. This works ok at slow speeds, but it’s jarring and completely fails to work at any speed where it might actually be useful.

  3. Added invisible guide rails on corners that push the player back when the “am I on the road ray” touches them. This worked ok, but if the player hit it at the wrong angle it would fling them off the road. Also, it failed at high speeds and was jittery looking.

  4. Turning on guard rails to keep the player on the road by basically making them a “bumper-car”. The troubles with this are that the car tends to get jammed when hitting a 90 degree wall or bounce up when hitting a any obtuse angle. It’s also way more work and objects, while also being rather annoying to actually play with and totally not what I had in mind.

Some things I have considered:

  1. I thought about making it a “cornering assist” only and putting a “path to object” (Steering Actuator) in both directions of every bend in the road. When the player’s “am I on the road ray” hits a trigger property, the player loses control and is sucked around the corner automatically. I think this would be effective, but it would be a lot of work to build. Update Feb 5th, 2016: I just pushed an update that shows this functionality in action (in one direction, for testing). It works, even moving the same navigation mesh and triggers around, but it looks twitchy (and did so even when I tried 900 faces around the bend lol…) This is probably what I will end up using - not perfect, but a workable solution.

  2. Constantly spawning an invisible object in front of the player and having the player path to that object, then destroy the object and repeat. The trick would be programming the spawner to search for and locate the center of the road even on turns.

The nice part is that all of my roads will be built using track pieces, so the 45, 90, and 180 turns are consistently sized and shaped. Thus if I go with only corner assist, I can reuse the method for all corners of the same type (and it will still work once I merge sections of tacks together into larger objects to reduce overlapping verts).

Thanks for your time and consideration!

Ps. In case you were wondering, this for a GPLv3 game I am working on as a hobby. You can find it here https://github.com/Tatwi/LoopDipole . I’m still building the world/roads/etc and working on the abilities/sounds/etc, but movement wise it’s functionally complete. Well, apart from the driving assist thing. :slight_smile: