Beispiel #1
0
def carHandler():

    vehicle = constraints.getVehicleConstraint(logic.car["cid"])

    ## calculate speed by using the back wheel rotation speed ##
    S = vehicle.getWheelRotation(2) + vehicle.getWheelRotation(3)
    logic.car["speed"] = (S - logic.car["dS"]) * 10.0

    ## apply engine force ##
    vehicle.applyEngineForce(logic.car["force"], 0)
    vehicle.applyEngineForce(logic.car["force"], 1)
    vehicle.applyEngineForce(logic.car["force"], 2)
    vehicle.applyEngineForce(logic.car["force"], 3)

    ## calculate steering with varying sensitivity ##
    if math.fabs(logic.car["speed"]) < 15.0: s = 2.0
    elif math.fabs(logic.car["speed"]) < 28.0: s = 1.5
    elif math.fabs(logic.car["speed"]) < 40.0: s = 1.0
    else: s = 0.5

    ## steer front wheels
    vehicle.setSteeringValue(logic.car["steer"] * s, 0)
    vehicle.setSteeringValue(logic.car["steer"] * s, 1)

    ## slowly ease off gas and center steering ##
    logic.car["steer"] *= 0.6
    logic.car["force"] *= 0.9

    ## align car to Z axis to prevent flipping ##
    logic.car.alignAxisToVect([0.0, 0.0, 1.0], 2, Stability)

    ## store old values ##
    logic.car["dS"] = S
def carHandler():

	vehicle = constraints.getVehicleConstraint(logic.car["cid"])

	## calculate speed by using the back wheel rotation speed ##
	S = vehicle.getWheelRotation(2)+vehicle.getWheelRotation(3)
	logic.car["speed"] = (S - logic.car["dS"])*10.0

	## apply engine force ##
	vehicle.applyEngineForce(logic.car["force"],0)
	vehicle.applyEngineForce(logic.car["force"],1)
	vehicle.applyEngineForce(logic.car["force"],2)
	vehicle.applyEngineForce(logic.car["force"],3)

	## calculate steering with varying sensitivity ##
	if math.fabs(logic.car["speed"])<15.0: s = 2.0
	elif math.fabs(logic.car["speed"])<28.0: s=1.5
	elif math.fabs(logic.car["speed"])<40.0: s=1.0
	else: s=0.5

	## steer front wheels
	vehicle.setSteeringValue(logic.car["steer"]*s,0)
	vehicle.setSteeringValue(logic.car["steer"]*s,1)

	## slowly ease off gas and center steering ##
	logic.car["steer"] *= 0.6
	logic.car["force"] *= 0.9

	## align car to Z axis to prevent flipping ##
	logic.car.alignAxisToVect([0.0,0.0,1.0], 2, Stability)
	
	## store old values ##
	logic.car["dS"] = S
Beispiel #3
0
def setWheelStats():
    # Apply handling stats to the (invisible) wheels
    vehicle = constraints.getVehicleConstraint(logic.car["cid"])
    # Grab base stats from "BaseStats" object
    bstat = logic.scene.objects["BaseStats"]
    # set vehicle roll tendency
    vehicle.setRollInfluence(bstat["influence"], 0)
    vehicle.setRollInfluence(bstat["influence"], 1)
    vehicle.setRollInfluence(bstat["influence"], 2)
    vehicle.setRollInfluence(bstat["influence"], 3)
    # set vehicle suspension hardness
    vehicle.setSuspensionStiffness(bstat["stiffness"], 0)
    vehicle.setSuspensionStiffness(bstat["stiffness"], 1)
    vehicle.setSuspensionStiffness(bstat["stiffness"], 2)
    vehicle.setSuspensionStiffness(bstat["stiffness"], 3)
    # set vehicle suspension dampness
    vehicle.setSuspensionDamping(bstat["damping"], 0)
    vehicle.setSuspensionDamping(bstat["damping"], 1)
    vehicle.setSuspensionDamping(bstat["damping"], 2)
    vehicle.setSuspensionDamping(bstat["damping"], 3)
    # set vehicle suspension compression ratio
    vehicle.setSuspensionCompression(bstat["compression"], 0)
    vehicle.setSuspensionCompression(bstat["compression"], 1)
    vehicle.setSuspensionCompression(bstat["compression"], 2)
    vehicle.setSuspensionCompression(bstat["compression"], 3)
    # set vehicle tire friction
    vehicle.setTyreFriction(bstat["friction"], 0)
    vehicle.setTyreFriction(bstat["friction"], 1)
    vehicle.setTyreFriction(bstat["friction"], 2)
    vehicle.setTyreFriction(bstat["friction"], 3)
Beispiel #4
0
def carInit():
    # setup aliases for Blender API access
    cont = logic.getCurrentController()
    logic.scene = logic.getCurrentScene()
    logic.car = cont.owner

    # Grab base stats from "BaseStats" object
    bstat = logic.scene.objects["BaseStats"]

    # Constants
    wheelRadius = bstat["wheelRadius"]
    wheelBaseWide = bstat["wheelBaseWide"]
    wheelFrontOffset = bstat["wheelFrontOffset"]
    wheelBackOffset = bstat["wheelBackOffset"]
    AttachHeightLocal = bstat["AttachHeightLocal"]
    suspensionLength = bstat["suspensionLength"]

    # setup general vehicle characteristics
    wheelAttachDirLocal = [0, 0, -1]
    wheelAxleLocal = [-1, 0, 0]

    # setup vehicle physics
    vehicle = constraints.createConstraint(logic.car.getPhysicsId(), 0,
                                           constraints.VEHICLE_CONSTRAINT)
    logic.car["cid"] = vehicle.getConstraintId()
    vehicle = constraints.getVehicleConstraint(logic.car["cid"])

    # Initialize variable to store speed so we can get the delta between frames
    logic.car["dS"] = 0.0

    # Attach the wheels to the bare object
    # (0)---(1)
    #    [|]
    # (2)---(3)
    wheel0 = logic.scene.objects["Wheel0"]
    wheelAttachPosLocal = [wheelBaseWide, wheelFrontOffset, AttachHeightLocal]
    vehicle.addWheel(wheel0, wheelAttachPosLocal, wheelAttachDirLocal,
                     wheelAxleLocal, suspensionLength, wheelRadius, 1)

    wheel1 = logic.scene.objects["Wheel1"]
    wheelAttachPosLocal = [-wheelBaseWide, wheelFrontOffset, AttachHeightLocal]
    vehicle.addWheel(wheel1, wheelAttachPosLocal, wheelAttachDirLocal,
                     wheelAxleLocal, suspensionLength, wheelRadius, 1)

    wheel2 = logic.scene.objects["Wheel2"]
    wheelAttachPosLocal = [wheelBaseWide, wheelBackOffset, AttachHeightLocal]
    vehicle.addWheel(wheel2, wheelAttachPosLocal, wheelAttachDirLocal,
                     wheelAxleLocal, suspensionLength, wheelRadius, 0)

    wheel3 = logic.scene.objects["Wheel3"]
    wheelAttachPosLocal = [-wheelBaseWide, wheelBackOffset, AttachHeightLocal]
    vehicle.addWheel(wheel3, wheelAttachPosLocal, wheelAttachDirLocal,
                     wheelAxleLocal, suspensionLength, wheelRadius, 0)

    # set the default values for anything that can be changed later
    resetStats()
    setWheelStats()
Beispiel #5
0
def createVehicle(GameObject):

    constraintType = constraints.VEHICLE_CONSTRAINT

    init_const = constraints.createConstraint(GameObject.getPhysicsId(), 0,
                                              constraints.VEHICLE_CONSTRAINT)
    init_vehicle = init_const.getConstraintId()
    vehicle = constraints.getVehicleConstraint(init_vehicle)
    return vehicle
Beispiel #6
0
def createVehicle(GameObject):

    constraintType = constraints.VEHICLE_CONSTRAINT

    init_const = constraints.createConstraint(
        GameObject.getPhysicsId(),
        0,
        constraints.VEHICLE_CONSTRAINT
    )
    init_vehicle = init_const.getConstraintId()
    vehicle = constraints.getVehicleConstraint(init_vehicle)
    return vehicle
Beispiel #7
0
    def getConstraint(self):
        owner = self.objects["Root"]

        if hasattr(constraints, "createVehicle") == True:
            vehicle = constraints.createVehicle(owner.getPhysicsId())
            self.cid = vehicle.getConstraintId()
        else:
            vehicle = constraints.createConstraint(
                owner.getPhysicsId(), 0, constraints.VEHICLE_CONSTRAINT)

            self.cid = vehicle.getConstraintId()
            vehicle = constraints.getVehicleConstraint(self.cid)

        return vehicle
Beispiel #8
0
def carHandler():
    # Apply max/top speed constraint (any time we aren't changing it)
    if logic.car["limitMaxVelocity"] == True:
        logic.car.linVelocityMax = logic.car["myLinVelocityMax"]

    vehicle = constraints.getVehicleConstraint(logic.car["cid"])

    # calculate speed by using the back wheel rotation and delta of value stored in the previous frame
    S = vehicle.getWheelRotation(2) + vehicle.getWheelRotation(3)
    logic.car["speed"] = (S - logic.car["dS"]) * 10.0

    # calculate world velocity, which is also valid while in the air. Raw value used for speedometer UI.
    Xspeed, Yspeed, Zspeed = logic.car.getLinearVelocity(True)
    linSum = Xspeed + Yspeed
    G.mySpeed = linSum

    # apply engine force
    vehicle.applyEngineForce(logic.car["force"] * 10, 0)
    vehicle.applyEngineForce(logic.car["force"] * 10, 1)
    vehicle.applyEngineForce(logic.car["force"] * 10, 2)
    vehicle.applyEngineForce(logic.car["force"] * 10, 3)

    # calculate steering with varying sensitivity
    if math.fabs(logic.car["speed"]) < 15.0: s = 2.0
    elif math.fabs(logic.car["speed"]) < 28.0: s = 1.5
    elif math.fabs(logic.car["speed"]) < 40.0: s = 1.0
    else: s = 0.5

    # steer front wheels
    vehicle.setSteeringValue(logic.car["steer"] * s, 0)
    vehicle.setSteeringValue(logic.car["steer"] * s, 1)

    # slowly ease off gas and center steering
    logic.car["steer"] *= 0.6
    logic.car["force"] *= 0.9

    # align to Z axis to prevent flipping
    bstat = logic.scene.objects["BaseStats"]
    logic.car.alignAxisToVect([0.0, 0.0, 1.0], 2, bstat["Stability"])

    # store old values
    logic.car["dS"] = S
    logic.car["dlinSum"] = linSum

    # Checks and status updates
    groundCheck()
    ribbonCheck()
    turboStatus()
    glideStatus()
Beispiel #9
0
def carHandler():
    vehicle = constraints.getVehicleConstraint(logic.car["cid"])

    # calculate speed by using the back wheel rotation speed
    S = vehicle.getWheelRotation(2)+vehicle.getWheelRotation(3)
    logic.car["speed"] = (S - logic.car["dS"])*10.0

    # calculate world velocity, which is also valid while in the air
    Xspeed, Yspeed, Zspeed = logic.car.getLinearVelocity(False)
    linSum = Xspeed + Yspeed + Zspeed
    G.mySpeed = linSum

    # hard limit velocity on the ground AND in the air every frame
    if abs(linSum) > logic.car.linVelocityMax:
        logic.car.linearVelocity[1] = logic.car.linVelocityMax - 4

    # apply engine force
    vehicle.applyEngineForce(logic.car["force"],0)
    vehicle.applyEngineForce(logic.car["force"],1)
    vehicle.applyEngineForce(logic.car["force"],2)
    vehicle.applyEngineForce(logic.car["force"],3)

    # calculate steering with varying sensitivity
    if math.fabs(logic.car["speed"])<15.0: s = 2.0
    elif math.fabs(logic.car["speed"])<28.0: s=1.5
    elif math.fabs(logic.car["speed"])<40.0: s=1.0
    else: s=0.5

    # steer front wheels
    vehicle.setSteeringValue(logic.car["steer"]*s,0)
    vehicle.setSteeringValue(logic.car["steer"]*s,1)

    # slowly ease off gas and center steering
    logic.car["steer"] *= 0.6
    logic.car["force"] *= 0.9

    # align car to Z axis to prevent flipping
    bstat = logic.scene.objects["BaseStats"]
    logic.car.alignAxisToVect([0.0,0.0,1.0], 2, bstat["Stability"])

    # store old values
    logic.car["dS"] = S

    # Checks
    groundCheck()
    ribbonCheck()
    turboStatus()
Beispiel #10
0
    def carConstraint(self, car):

        #get physics ID
        carPhysicsID = car.getPhysicsId()

        #create a vehicle constraint
        vehicleConstraint = constraints.createConstraint(carPhysicsID, 0, 11)

        #get the constraint ID
        constraintID = vehicleConstraint.getConstraintId()

        #get the vehicle constraint ID
        vehicleID = constraints.getVehicleConstraint(constraintID)

        #save vehicle constraint ID as an object variable
        car["vehicleID"] = vehicleID

        #return vehicle ID
        return vehicleID
Beispiel #11
0
    def add_constraint(self):

        if self.constraint is not None:
            return

        # create and store vehicle constraint

        constraint = constraints.createConstraint(
            self.getPhysicsId(), 0, constraints.VEHICLE_CONSTRAINT)
        self.constraint = constraints.getVehicleConstraint(
            constraint.getConstraintId())

        # move wheels to vehicle constraint and set values (and remove collision objects)

        for i, wheel in enumerate(self.wheels):
            wheel.removeParent()

            susp_rest_len = self.WHEELS_SUSP_REST_LEN[i]
            attach_pos = self.wheels[wheel].xyz
            attach_pos.z += susp_rest_len
            down_dir = WHEELS_DOWN_DIR
            axle_dir = WHEELS_AXLE_DIR
            radius = (utils.get_dimensions(wheel).z * wheel.localScale.z) * 0.5
            has_steering = WHEELS_HAS_STEERING[i]

            self.constraint.addWheel(wheel, attach_pos, down_dir, axle_dir,
                                     susp_rest_len, radius, has_steering)

            self.constraint.setTyreFriction(self.FRICTION_VAL, i)
            self.constraint.setSuspensionDamping(self.DAMPING_VAL, i)
            self.constraint.setSuspensionCompression(self.COMPRESSION_VAL, i)
            self.constraint.setSuspensionStiffness(self.STIFFNESS_VAL, i)
            self.constraint.setRollInfluence(self.ROLL_VAL, i)

            if self.wheel_col_name in wheel.children:
                wheel.children[self.wheel_col_name].endObject()

        # apply steering value

        self.constraint.setSteeringValue(self.steering_val, 0)
        self.constraint.setSteeringValue(self.steering_val, 1)
def Car_Constraint(carObj):

    # # import PhysicsConstraints
    # import PhysicsConstraints
        
    # get physics ID
    car_PhysicsID = carObj.getPhysicsId()
     
    # create a vehicle constraint 
    # vehicle_Constraint = PhysicsConstraints.createConstraint(car_PhysicsID, 0, 11)
    vehicle_Constraint = constraints.createConstraint(car_PhysicsID, 0, constraints.VEHICLE_CONSTRAINT)
     
    # # get the constraint ID
    constraint_ID = vehicle_Constraint.getConstraintId()
      
    # # get the vehicle constraint ID
    vehicleID = constraints.getVehicleConstraint(constraint_ID)

    # save vehicle constraint ID as an object variable
    carObj["vehicleID"] = vehicleID

    return vehicleID    
Beispiel #13
0
def Car_Constraint(carObj):

    # # import PhysicsConstraints
    # import PhysicsConstraints

    # get physics ID
    car_PhysicsID = carObj.getPhysicsId()

    # create a vehicle constraint
    # vehicle_Constraint = PhysicsConstraints.createConstraint(car_PhysicsID, 0, 11)
    vehicle_Constraint = constraints.createConstraint(
        car_PhysicsID, 0, constraints.VEHICLE_CONSTRAINT)

    # # get the constraint ID
    constraint_ID = vehicle_Constraint.getConstraintId()

    # # get the vehicle constraint ID
    vehicleID = constraints.getVehicleConstraint(constraint_ID)

    # save vehicle constraint ID as an object variable
    carObj["vehicleID"] = vehicleID

    return vehicleID
def carInit():
	## setup aliases for Blender API access ##
	cont = logic.getCurrentController()
	logic.scene = logic.getCurrentScene()
	logic.car  = cont.owner

	## setup general vehicle characteristics ##
	wheelAttachDirLocal = [0,0,-1]
	wheelAxleLocal = [-1,0,0]

	## setup vehicle physics ##
	vehicle = constraints.createConstraint(logic.car.getPhysicsId(), 0, constraints.VEHICLE_CONSTRAINT)
	logic.car["cid"] = vehicle.getConstraintId()
	vehicle = constraints.getVehicleConstraint(logic.car["cid"])

	## initialize temporary variables ##
	logic.car["dS"] = 0.0

	## attached wheel based on actuator name ##
	wheel0 = logic.scene.objects["Wheel0"]
	wheelAttachPosLocal = [wheelBaseWide ,wheelFrontOffset, AttachHeightLocal]
	vehicle.addWheel(wheel0,wheelAttachPosLocal,wheelAttachDirLocal,wheelAxleLocal,suspensionLength,wheelRadius,1)

	wheel1 = logic.scene.objects["Wheel1"]
	wheelAttachPosLocal = [-wheelBaseWide ,wheelFrontOffset, AttachHeightLocal]
	vehicle.addWheel(wheel1,wheelAttachPosLocal,wheelAttachDirLocal,wheelAxleLocal,suspensionLength,wheelRadius,1)

	wheel2 = logic.scene.objects["Wheel2"]
	wheelAttachPosLocal = [wheelBaseWide ,wheelBackOffset, AttachHeightLocal]
	vehicle.addWheel(wheel2,wheelAttachPosLocal,wheelAttachDirLocal,wheelAxleLocal,suspensionLength,wheelRadius,0)

	wheel3 = logic.scene.objects["Wheel3"]
	wheelAttachPosLocal = [-wheelBaseWide ,wheelBackOffset, AttachHeightLocal]
	vehicle.addWheel(wheel3,wheelAttachPosLocal,wheelAttachDirLocal,wheelAxleLocal,suspensionLength,wheelRadius,0)

	## set vehicle roll tendency ##
	vehicle.setRollInfluence(influence,0)
	vehicle.setRollInfluence(influence,1)
	vehicle.setRollInfluence(influence,2)
	vehicle.setRollInfluence(influence,3)

	## set vehicle suspension hardness ##
	vehicle.setSuspensionStiffness(stiffness,0)
	vehicle.setSuspensionStiffness(stiffness,1)
	vehicle.setSuspensionStiffness(stiffness,2)
	vehicle.setSuspensionStiffness(stiffness,3)

	## set vehicle suspension dampness ##
	vehicle.setSuspensionDamping(damping,0)
	vehicle.setSuspensionDamping(damping,1)
	vehicle.setSuspensionDamping(damping,2)
	vehicle.setSuspensionDamping(damping,3)

	## set vehicle suspension compression ratio ##
	vehicle.setSuspensionCompression(compression,0)
	vehicle.setSuspensionCompression(compression,1)
	vehicle.setSuspensionCompression(compression,2)
	vehicle.setSuspensionCompression(compression,3)

	## set vehicle tire friction ##
	vehicle.setTyreFriction(friction,0)
	vehicle.setTyreFriction(friction,1)
	vehicle.setTyreFriction(friction,2)
	vehicle.setTyreFriction(friction,3)
Beispiel #15
0
def car_init():

	## setup aliases for Blender API access ##
	cont = logic.getCurrentController()
	logic.scene = logic.getCurrentScene()
	#logic.car  = cont.owner


	logic.car["start_time"] = 0
	#print("{} - {}".format(time.time(), logic.car["start_time"]))

	## setup general vehicle characteristics ##
	wheelAttachDirLocal = [0,0,-1]
	wheelAxleLocal = [-1,0,0]

	## setup vehicle physics ##
	vehicle = constraints.createConstraint(
		logic.car.getPhysicsId(), 0, constraints.VEHICLE_CONSTRAINT)
	

	if(vehicle.getConstraintId() == 0): end_game()
	
	logic.car["cid"] = vehicle.getConstraintId()
	vehicle = constraints.getVehicleConstraint(logic.car["cid"])


	## initialize temporary variables ##
	logic.car["dS"] = 0.0
	logic.car["force"]  = 0.0
	logic.car["steer"]  = 0.0
	logic.car["jump"]  = 0.0
	logic.car["steer_val"] = 0.0
	logic.car["steer_s"] = 0.0
	logic.car["km_h"] = 0.0
	logic.car["braking_time"] = 0.0
	logic.car["steeringR"] = 0.0
	logic.car["steeringL"] = 0.0
	logic.car["steering"] = False
	logic.car["theta"] = 0.0
	logic.car["time"] = 0
	
	logic.car["braking"] = False
	logic.car["ended"] = False

	car_pos = logic.car.worldPosition

	## attached wheel based on actuator name ##

	wheels = ['w0l', 'w0r', 'w1l', 'w1r']
	wheels_engine = [1, 1, 0, 0]

	for i in range(len(wheels)):
		wheel_name = wheels[i]
		wheel = logic.scene.objects[wheel_name]
		wheel_pos = wheel.worldPosition
		wheel_local = wheel_pos - car_pos - mathutils.Vector((0.0, 0.0, wheel_height))#wheel_height - suspensionLength))

		vehicle.addWheel(
			wheel,
			wheel_local,
			wheelAttachDirLocal,
			wheelAxleLocal,
			suspensionLength,
			wheel_radius,
			wheels_engine[i])
		
		## set vehicle roll tendency ##
		#vehicle.setRollInfluence(influence, i)
		## set vehicle suspension hardness ##
		vehicle.setSuspensionStiffness(stiffness, i)
		## set vehicle suspension dampness ##
		vehicle.setSuspensionDamping(expansion, i)
		## set vehicle suspension compression ratio ##
		vehicle.setSuspensionCompression(compresion, i)
Beispiel #16
0
def car_update():

	#print("car update")
	vehicle = constraints.getVehicleConstraint(logic.car["cid"])

	## calculate speed by using the back wheel rotation speed ##
	S = vehicle.getWheelRotation(2)+vehicle.getWheelRotation(3)
	logic.car["speed"] = (S - logic.car["dS"])*10.0

	wheel_v = logic.scene.objects['w1l'].getLinearVelocity(True)
	pos = logic.car.worldPosition
	lpos = logic.car.localPosition
	vel = logic.car.getLinearVelocity(False)
	#draw_vec(pos+mathutils.Vector((0,0,1)), vel)
	#draw_vec(pos+mathutils.Vector((0,0,1)), mathutils.Vector((1,0,0)))
	#draw_vec(pos+mathutils.Vector((0,0,1)), mathutils.Vector(rf), [1,0,0])
#	draw_vec(pos, mathutils.Vector((1,0,)))
	#draw_vec(pos, wheel_v)
	#print(wheel_v)
	#print(logic.car.worldOrientation.to_euler())
	#print("------------------------")
	

	if logic.car["start_time"] == 0:
		logic.car["start_time"] = int(time.time()*1000)

	if not logic.car["ended"]:
		now = time.time()
		tiempo = int(now*1000) - logic.car["start_time"]
		cent = int(tiempo/10 % 100)
		segundos = int(tiempo/1000)%60
		minutos = int(tiempo/(1000*60))
		set_text_time("{m:02d}:{s:02d}:{c:02d}".format(
			m=minutos, s=segundos, c=cent))
		set_text_finish("")
		
		logic.car["time"] = tiempo
	else:
		set_text_finish("META")
		now = time.time()
		esperado = int(now*1000 - logic.car["start_time"] - logic.car["time"])
		if esperado > 3 * 1000:
			game_back()
	

	#f = mathutils.Vector(logic.car.getReactionForce()) * 3
	#print(f)
	#draw_vec(mathutils.Vector((0,0,0)), f)
	velm = math.sqrt(vel[0]**2 + vel[1]**2 + vel[2]**2)
	#print(linSum)



	## brake back wheels
	if logic.car["braking"]:
		logic.car["braking_time"] += 1
		braking_time = logic.car["braking_time"]

		car_friction(vehicle, 1.45, 0.28)
		car_influence(vehicle, 1, 1)
		car_power(vehicle, logic.car["force"], 0)
		car_brake(vehicle, 0, 1.45)
	else:
		logic.car["braking_time"] = 0
		car_friction(vehicle, 1.9, 2)
		car_influence(vehicle, 0.9, 0.8)
		car_power(vehicle, logic.car["force"], logic.car["force"] * rear_force)
		car_brake(vehicle, 0, 0)

	## calculate steering with varying sensitivity ##

	speed = math.fabs(logic.car["speed"])
	log_speed = math.log(speed * 0.06 + 1)
	#s = 2 - log_speed
	s = 2 - math.pow(speed * 0.06, 1/3)
	if s < 0.03: s = 0.03

	steer_val = logic.car["steer"] * 1 * s

	log_steer = max(1-math.log(speed+30)/5, 0.03)
	#print(steer_val)
	logic.car["steer_val"] = log_steer
	logic.car["steer_s"] = log_steer
	logic.car["km_h"] = velm

#	if math.fabs(logic.car["speed"])<15.0: s = 2.0
#	elif math.fabs(logic.car["speed"])<28.0: s=1.5
#	elif math.fabs(logic.car["speed"])<40.0: s=1.0
#	else: s=0.5

	## steer front wheels
	#vehicle.setSteeringValue(logic.car["steer"] * s,0)
	#car_steer(vehicle, steer_val)

	## align car to Z axis to prevent flipping ##
	logic.car.alignAxisToVect([0.0,0.0,1.0], 2, Stability)
	
	## store old values ##
	logic.car["dS"] = S

	logic.car["jump"] += 0.1
	update_steer(vehicle)
Beispiel #17
0
def carInit():
    ## setup aliases for Blender API access ##
    cont = logic.getCurrentController()
    logic.scene = logic.getCurrentScene()
    logic.car = cont.owner

    ## setup general vehicle characteristics ##
    wheelAttachDirLocal = [0, 0, -1]
    wheelAxleLocal = [-1, 0, 0]

    ## setup vehicle physics ##
    vehicle = constraints.createConstraint(logic.car.getPhysicsId(), 0,
                                           constraints.VEHICLE_CONSTRAINT)
    logic.car["cid"] = vehicle.getConstraintId()
    vehicle = constraints.getVehicleConstraint(logic.car["cid"])

    ## initialize temporary variables ##
    logic.car["dS"] = 0.0

    ## attached wheel based on actuator name ##
    wheel0 = logic.scene.objects["Wheel0"]
    wheelAttachPosLocal = [wheelBaseWide, wheelFrontOffset, AttachHeightLocal]
    vehicle.addWheel(wheel0, wheelAttachPosLocal, wheelAttachDirLocal,
                     wheelAxleLocal, suspensionLength, wheelRadius, 1)

    wheel1 = logic.scene.objects["Wheel1"]
    wheelAttachPosLocal = [-wheelBaseWide, wheelFrontOffset, AttachHeightLocal]
    vehicle.addWheel(wheel1, wheelAttachPosLocal, wheelAttachDirLocal,
                     wheelAxleLocal, suspensionLength, wheelRadius, 1)

    wheel2 = logic.scene.objects["Wheel2"]
    wheelAttachPosLocal = [wheelBaseWide, wheelBackOffset, AttachHeightLocal]
    vehicle.addWheel(wheel2, wheelAttachPosLocal, wheelAttachDirLocal,
                     wheelAxleLocal, suspensionLength, wheelRadius, 0)

    wheel3 = logic.scene.objects["Wheel3"]
    wheelAttachPosLocal = [-wheelBaseWide, wheelBackOffset, AttachHeightLocal]
    vehicle.addWheel(wheel3, wheelAttachPosLocal, wheelAttachDirLocal,
                     wheelAxleLocal, suspensionLength, wheelRadius, 0)

    ## set vehicle roll tendency ##
    vehicle.setRollInfluence(influence, 0)
    vehicle.setRollInfluence(influence, 1)
    vehicle.setRollInfluence(influence, 2)
    vehicle.setRollInfluence(influence, 3)

    ## set vehicle suspension hardness ##
    vehicle.setSuspensionStiffness(stiffness, 0)
    vehicle.setSuspensionStiffness(stiffness, 1)
    vehicle.setSuspensionStiffness(stiffness, 2)
    vehicle.setSuspensionStiffness(stiffness, 3)

    ## set vehicle suspension dampness ##
    vehicle.setSuspensionDamping(damping, 0)
    vehicle.setSuspensionDamping(damping, 1)
    vehicle.setSuspensionDamping(damping, 2)
    vehicle.setSuspensionDamping(damping, 3)

    ## set vehicle suspension compression ratio ##
    vehicle.setSuspensionCompression(compression, 0)
    vehicle.setSuspensionCompression(compression, 1)
    vehicle.setSuspensionCompression(compression, 2)
    vehicle.setSuspensionCompression(compression, 3)

    ## set vehicle tire friction ##
    vehicle.setTyreFriction(friction, 0)
    vehicle.setTyreFriction(friction, 1)
    vehicle.setTyreFriction(friction, 2)
    vehicle.setTyreFriction(friction, 3)