Racing game help.

I am trying to make a racing game using BGE. I would like to include the “ghost” feature that so many games have (where you can race against a ghost of your fastest time). I cannot find any tutorials on how to do this, and I am a beginner and don’t have a clue on how to do it. Anyone know of a tutorial, or something that can help? Thanks in advance.

How about record your current race, save it to file (if better than the already saved record). The next race you load that data and replay with a ghost like object.

You need Python to do the recording. Look for save/load.

Hint: TimeShift - record location and orientation, replay it later at another object [without file operations]

Thank you for your help!

I’m programming a recording system and I will be done with it soon. I will let you know when it’s done and hopefully you will be able to implement it.

Oohh hey man i was wondering if it is also possible to record the whole Race and do Replays?
because in my project iam trying to create an additional feature that will give the player the ability to review his/her previous race.

Possible solution:
create a global dictionary(for example, create it in bge.logic.globalDict)


import bge
import json
gd = bge.logic.globalDict
if not "record" in gd:
    gd["record"] = {}
    gd["frame"] = 0

than in each frame you do this for your car:


pos = car.worldPosition
rot = car.orientation
# Here you can store other data, if needed
frame = gd["frame"]
gd["frame"] += 1
data = {"pos": pos, "rot": rot}
gd["record"][str(frame)] = data

After the race you save it all down in a file, that’s why we imported json.


path = bge.logic.expandPath("//") # You can adjust the path there
filename = "record.json" # The file must already be there, though, make sure that you pack it with the game:)
fp = path + filename
if laptime < recordtime: # This you must obtain somewhere else
    json.dump(gd["record"], open(fp, 'w'))

and than on the ghost you do:


import bge
import json
path = bge.logic.expandPath("//")
filename = "record.json"
fp = path + filename
gd = bge.logic.globalDict
if not "oldrecord" in gd:
    gd["oldrecord"] = json.load(open(fp))
f = str(gd["frame"])
ghost.worldPosition = gd["oldrecord"][f]["pos"]
ghost.orientation = gd["oldrecord"][f]["rot"]

This should most likely work;)

Yes, the purpose of my system is to record gameplay so you can watch your gameplay, and rewind it. I will probably be working on it for a few more days.

Wow thanks I am looking forward towards it man.
Thanks adriansnetlis I will give it a shot as well man.

well thank you very much Nicholas_A , iam sure that it will be of good use in our Game projects.
I will give you Feedback when I will be done with my Pre-Alpha Demo for the year.

Fred/K.S