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
- Every few seconds:
Leave a comment
Recent posts
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
- Check if point is inside polygon 2D (using line intersection)
- UnityHub: Enable Create Project Button (without having to select Cloud Organization)
- UI: Make Tooltip background fit Text content length
- Pong-Wars in Unity
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub)
- UnityHub: Add support for custom project title (instead of folder name) or use ProductName
- Testing Unity MUSE AI