![Dani's Race Screenshot [embedded image]](/pictures/danisrace/DRscreens/26.jpg)
GARAGE which is the cheat-code to teleport to the garage. As soon as I do that, the game spawns in the cars it has recorded into the save-file. And the NaN bug occurs. GOOD! Perfect. Now let's dig.
↩ Reply
JSON formatted version of it, that I can dump into a file, generated by 2 functions in Scripts.Vehicle.py. Specifically the functions Encode and Decode.
↩ Reply
Encode function is straight forward. It just takes whatever relevant info the car has and formats it such that it all could be dumped into JSON.
↩ Reply
Decode part is interesting.
↩ Reply
if "position" in changed: newposition = client.extrapolate(car.position.copy(), data.get("position", (0,0,0)), obj = car) Reuse.Move(car, newposition)
client.extrapolate function that tries to smooth out the positions of the cars received from the network. And the Reuse.Move function that tries to lower the impact of moving cars around on Depsgraph.
↩ Reply
Reuse.Move function looks like this:
↩ Reply
def Move(object, position, times=1): # Moving object using applyMovement object.applyMovement( ( mathutils.Vector(position) - object.position ) * times )
car.position? And frankly I don't have enough science to see if it works the way it should. If anything, on paper it looks to be slower than writing the position directly. But... Depsgraph is a bitch. And it feels like using this actually improves performance a little bit.
↩ Reply
object.applyMovement instead, it doesn't need to recalculate anything. So I could give it only the difference of where it is, to where I want it to be ( which is trivial to calculate, as it is just 3 subtractions (xyz) ), and hopefully it will give me a way to move objects a little bit faster.
↩ Reply
python ( the language of the code of the game ) is to do float("nan"). As in, to literally tell python that I want specifically a NaN. I tried diving by zero and it just gave me errors. Like it should. I tried messing with precisions. It wouldn't budge. But I know at least one program in C++ susceptible to NaNs. Specifically Bullet Physics. Which coincidentally is the physics engine in the game engine I'm using for my game. And coincidentally the game engine is as well, written in C++.
↩ Reply
Reuse.Move function just won't budge. It is not it. It doesn't do the NaNs.
↩ Reply
client.extrapolate
↩ Reply
def extrapolate(original, value, obj=None, objKey="position"): # This function will extrapolate motion # of objects. # Make sure both are Vectors if obj: try: original = obj["net-finals"][objKey].copy() except: pass original = mathutils.Vector(original) value = mathutils.Vector( value ) # Calculate time offset offset = time.time() - queue.get("time", time.time()) frame = queue.get("time", time.time()) - queue.get("tick", time.time()) # caluclating the values diff = value - original withext = diff * ( frame + offset ) final = original + withext + diff # Smoothing data for the object. if obj: if "net-exp" not in obj: obj["net-exp"] = {} obj["net-finals"] = {} obj["net-originals"] = {} obj["net-exp"][objKey] = ( diff + withext ) * ( ( 1 / ( frame + offset ) ) / bge.logic.getAverageFrameRate() ) obj["net-exp"]["time"] = int(round(( frame + offset ) * bge.logic.getAverageFrameRate())) obj["net-exp"]["time-full"] = obj["net-exp"]["time"] obj["net-finals"][objKey] = final obj["net-originals"][objKey] = original return final
Decode. The cars spawns good. What the actual fuck?
↩ Reply
PhysicsUpdate ?
↩ Reply
def PhysicsUpdate(car): # Updating the car physics to # work with a more realistic # effect, while cheating at some # things. scene, car = GetSceneAndCar(car) toFPS = Opt.ToFPS() carD = Opt.FastDict(car) # If car has no physics yet, give it physics initfirst = False if not getCarPhysics(car): InitCarPhysics(car) initfirst = True # Forces ( Drag Force, Down Force ) x = 0 z = -DownForce(car) df = DragForce(car) car.applyForce(df, False) car.applyForce([0, 0, z], not car.get("underwater", False)) dirt = False ground = OnGround(car) if "ground" in str(ground).lower(): dirt = True s = 50 * abs(car.localLinearVelocity.y) vec = (random.uniform(-s, s), random.uniform(-s, s), 0) car.applyTorque(vec, True) if car.get("active") and ( dirt or ( abs(car.localLinearVelocity.x) > 2 and ground ) ) : speed = math.dist((0,0,0), car.localLinearVelocity) if speed > 10: Input.VibrateJoystick(speed/100, -car.localLinearVelocity.x) if car.get("active") or Opt.GoodFPS(str(id(car))+"_physics") or initfirst: GetPhysicsForces(car) SwingDoors(car) for n, wheel in enumerate(car["specs"]["wheels"]): wheelObject = car["wheels"][n] health = wheelObject["health"] ** 2 # Damping suspension = wheelObject["suspension"] * health hbf = 1.0 if car.get("handbraking"): if not wheel.get("front"): hbf = 0.5 else: hbf = 0.6 # Increasing suspension based on how much # the wheel is pressed against the bottom of the car. #if car["specs"].get("suspentionCorrect", True): #hight = car.getVectTo(wheelObject.position)[2][2] #if hight > 0: # suspension = suspension * max(1, ( 1 + ( ( hight ) * 20 ) )) #suspension += abs(z)/10 k = car["specs"]["suspentionDamping"] suspensionDamping = 2 * k * math.sqrt(suspension) getCarPhysics(car).setSuspensionStiffness(suspension, n) getCarPhysics(car).setSuspensionDamping(suspensionDamping, n) DFS = car["specs"].get("driftSpeed", 50) DRIFTINESS = car["specs"].get("driftiness", 1) DF = max(0, min(1, abs(car.worldLinearVelocity.y) / DFS ) ) if car.get("breaking"): DF = 1.0 try: DFT = max(0, min(1, (math.dist((0,0,0),car.localAngularVelocity) / car["specs"].get("maxAngularVelocity", 1.5)) / DF ) ) except: DFT = 0.0 DF *= DFT grip = car["specs"]["grip"] if (car.localAngularVelocity.z > 0) != (car.localLinearVelocity.x > 0): dgrip = wheel.get("drift_grip", car["specs"]["grip"]) grip = (grip*(1-DF)) + (dgrip * DF) car["DriftFactor"] = DF # if car.get("breaking"): # DFS /= 10 # DRIFTINESS *= 10 # DF = 1 / max(1, abs( car.localLinearVelocity.y ) / DFS ) # if abs(car.localAngularVelocity.z) >= car["specs"].get("maxAngularVelocity", 1.5) * DF\ # and Turning(car) >= (DF/2) : # grip = wheel.get("drift_grip", car["specs"]["grip"]) # car.applyTorque(car.localAngularVelocity*10*DRIFTINESS, True) # else: # grip = car["specs"]["grip"] # Simulating sand and dirt and stuff. roll = car["specs"]["roll"] if dirt: grip *= 0.4 roll += 0.8 grip = grip*math.sqrt(car.mass)*hbf getCarPhysics(car).setTyreFriction(grip, n) getCarPhysics(car).setRollInfluence(roll, n) # Applying the engine acceleration # to the wheels. ApplyEngine(car) # Making sure to clear the acceleration # for the next frame. # if not car.get("braking"): # car["driftturn"] = 0.0 car["accelerating"] = False car["braking"] = False
getCarPhysics(car).setTyreFriction(grip, n) or something there is NaN. I disable all this code. No... Still NaNs. What?
↩ Reply
ApplyEngine(car)
↩ Reply
Apply fucking Engine(car) !!!
↩ Reply
def ApplyEngine(car): carD = Opt.FastDict(car) toFPS = Opt.ToFPS() hp = HorsePower(car) force = HorsePowerToWatts(hp) / 100 grip = car["specs"]["grip"] # Here is a little cheat to help the car start notresistance = EngineResistance(car) if car.get("gear",0) == 0: notresistance = 1 FO = force * notresistance / GetGearRatio(car) / grip T = time.time() if force > 0: D = max(0, FO - carD["prevF"]) else: D = min(0, FO - carD["prevF"]) # TODO, this is a temporary fix. For some reason small cars such # as scooter and kart overaccelerate when this is turned on. # The math is designed to give players the same acceleration across # different performances. # TODO, investigate this for causing strange NaN bugs. # So fart the car.get("accelerating") stops most of it # from happening. But maybe there is more to it. if car.get("accelerating") and car["specs"].get("type") not in ("skating vehicle", "kart"): try: calc = ( 1 / ( D * ( ( T - carD["prevT"] ) ** 2 ) ) ) F = FO + calc except: F = FO else: F = FO carD["prevT"] = time.time() carD["prevF"] = FO for n, wheel in enumerate(car["specs"]["wheels"]): wheelObject = car["wheels"][n] health = (wheelObject["health"] + carD["health"]) / 2 rightwheel = ( wheel["front"] and force > 0 ) or ( not wheel["front"] and force < 0 ) if rightwheel and ( not car.get("braking") or car.get("drifting") ): getCarPhysics(car).applyEngineForce(F * health, n) else: getCarPhysics(car).applyEngineForce(0, n) # Decrease RPMS if not car.get("accelerating") and not NetworkControlled(car): carD["rpm"] *= 0.98 * EngineResistance(car)
( 1 / ( D * ( ( T - carD["prevT"] ) ** 2 ) ) )
RowdyJoe
c:0 July 04, 2026![[thumbnail]](/pictures/user_upload/Troler/NGWJ6K0NF96N3RYQ.png)
Trolergit for this game. Instead, most changes will be recorded via the notgit.py program I wrote for fun the other day.
9ACHJKSXN3. Imagine having a bunch of those randomly generated codes marking a bunch of stuff in your inventory or something. Imagine needing to constantly type those in every-time you do something with those things in the inventory. Imagine you have to do that on a fucking touch-screen, on a broken Gnome screen-keyboard, on a slow ass device not meant for running Gnome. QR codes sounds like a very good idea. But there is another problem. You need to print those. You need to print those fast and cheaply. You can't draw them. And the receipt printer is not even working. So... did I do that?