Jan
31
2018

Checking Last Known Good Position For A Car In The Track

Working on a small StuntCarRacer-inspired game with a friend.
Some note here about how to get car to return last known good position in the track.

Problems and Requirements

– Player gets stuck hanging in side of the track (1 or more tires hanging outside, cannot move)
– Player falls off from the track
– Should allow respawning into last known good position on the track
– Should reset player rotation towards correct direction

Solutions

  •  Trigger Checkpoints
    • Everytime you enter a trigger, record this as a last good position
    • Should work very nicely, but either need to manually place the triggers or have some logic to automatically do that, which could become difficult with complicated tracks
      • You could manually place dummy objects in 3D modelling tool while making the track, to mark the trigger positions
    • This would easily solve correct rotation (take from trigger forward)
  • Take Closest Track Position
    • Could raycast around the car to find closest track position and lift car to the track on that point
    • Cannot be used, because if you fall of the track, driving in the ground is allowed (so you could take shortcuts then)
  • Take Last Hit Point From Track
    • Kind of works, but often that point could be already barely touching the track and player then falls off again
  • Record Last Known Good Hit Point *Currently using this method
    • Every few seconds:
      • Check that every tire hits the track
      • Check that every tire slope angle is below threshold (like 10° to avoid re-spawning in steep locations)
    • Only issue is that correct rotation is difficult to get, if player was driving in wrong direction, he will be respawned towards that direction also

 

 


About the Author:

.fi

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Github Join Discord Twitch Instagram BlueSky

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.