def OnCollisionDo(obj, point, normal, points):
if car["active"] or (InView(car) and Opt.GoodFPS("Collision"),0.6):
OnCollision(car, obj, point, normal, points)
car.collisionCallbacks.append(OnCollisionDo)
for point in list(points)[:2]:
force = point.appliedImpulse / car.mass / 2
def SwingDoors(car):
reference = ( car["localLinearForces"] + car.localLinearVelocity ) / 2
for door in car.get("doors",[]):
if door.get("locked", True) or not door.visible:
continue
minrot = door.get("minrot", 0)
maxrot = door.get("maxrot", math.pi/2)
lockat = door.get("lockat", 0)
breakat= door.get("breakat", math.pi/2)
axis = door.get("axis", 2)
factor = door.get("factor", 1.0)
offset = door.get("offset", math.pi)
rot = door.localOrientation.to_euler()
rot[axis] = (math.atan2(*(i for n, i in enumerate(reference) if n != axis )) + offset ) * factor
for n in range(3):
if n != axis:
rot[n] = 0
if door.get("gravity", axis != 2):
if axis == 1: gravityaxis = 2
else : gravityaxis = 1
gravityfactor = reference[gravityaxis]
if gravityfactor < 0: gravityfactor *= -1
gravityfactor = min(30, gravityfactor)/30
gravityfactor = 1 - gravityfactor
rot[axis] = rot[axis]+((lockat - rot[axis])*gravityfactor)
maxrot -= minrot
rot[axis] -= minrot
if rot[axis] < 0: rot[axis] += math.pi*2
if rot[axis] > (maxrot/2)+math.pi:
rot[axis] = 0
elif rot[axis] > maxrot:
rot[axis] = maxrot
rot[axis] += minrot
oldrot = door.localOrientation.to_euler()[axis]
diff = ( rot[axis] - oldrot )
if diff > math.pi: diff -= math.pi*2
elif diff < -math.pi: diff += math.pi*2
rot[axis] = oldrot + ( diff / 5 )
door.localOrientation = rot
if door["health"] > 0.5 and round(rot[axis],2) == round(lockat, 2):
door["locked"] = True
rot[axis] = lockat
if round(rot[axis],3) == round(breakat, 3):
door["health"] -= 0.003
if door["health"] < 0.1:
door.visible = False
newdoor = Reuse.Create(door.name, 500)
if "Borked" in door:
newdoor.replaceMesh(door["Borked"])
newdoor.position = door.position
newdoor.orientation = door.orientation
newdoor.worldLinearVelocity = car.worldLinearVelocity / 1.5
ColorPart(car, newdoor)