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()
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
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
def soft_body_pin(softbodyobj, controls): """ Pins the soft body object to an object using its vertices (a control object). It will pin the soft-body object to all of the vertices of all of the objects in the controls list. So, for controls pass a list like: [ControlObject, ControlObject2, etc.] where ControlObject are Game Objects fetched through the scene list, for example. """ softid = softbodyobj.getPhysicsId() ctype = 2 # Constraint type, 1 = edge; 0 = point, 2 = angular? for c in controls: cid = c.getPhysicsId() for vert in range(c.meshes[0].getVertexArrayLength(0)): vpos = c.meshes[0].getVertex(0, vert).getXYZ() constraints.createConstraint(softid, cid, ctype, vpos[0], vpos[1], vpos[2], 8, -1, 0.5)
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
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
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
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 createChain(markerA, markerB, nuggets): return PhyIDA = markerA.getPhysicsId() PhyIDB = markerB.getPhysicsId() consType = 12 # 6dof for i, nug in enumerate(nuggets): PhyIDNug = nug.getPhysicsId() if i == 0: print('linking head to first nug') constraints.createConstraint(PhyIDA, PhyIDNug, consType) elif i == len(nuggets)-1: print('linking nug to end') constraints.createConstraint(PhyIDNug, PhyIDB, consType) else: print('linking nug to nug') PhyIDNext = nuggets[i+1].getPhysicsId() constraints.createConstraint(PhyIDNug,PhyIDNext, consType)
# get object list objects = logic.getCurrentScene().objects # get object named Object1 and Object 2 object_1 = objects["Object1"] object_2 = objects["Object2"] # want to use Edge constraint type constraint_type = 2 # get Object1 and Object2 physics IDs physics_id_1 = object_1.getPhysicsId() physics_id_2 = object_2.getPhysicsId() # use bottom right edge of Object1 for hinge position edge_position_x = 1.0 edge_position_y = 0.0 edge_position_z = -1.0 # rotate the pivot z axis about 90 degrees edge_angle_x = 0.0 edge_angle_y = 0.0 edge_angle_z = 90.0 # create an edge constraint constraints.createConstraint(physics_id_1, physics_id_2, constraint_type, edge_position_x, edge_position_y, edge_position_z, edge_angle_x, edge_angle_y, edge_angle_z)
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)
# get object list objects = logic.getCurrentScene().objects # get object named Object1 and Object 2 object_1 = objects["Object1"] object_2 = objects["Object2"] # want to use Edge constraint type constraint_type = 2 # get Object1 and Object2 physics IDs physics_id_1 = object_1.getPhysicsId() physics_id_2 = object_2.getPhysicsId() # Use bottom right edge of Object1 for hinge position edge_position_x = 1.0 edge_position_y = 0.0 edge_position_z = -1.0 # use Object1 y axis for angle to point hinge edge_angle_x = 0.0 edge_angle_y = 1.0 edge_angle_z = 0.0 # create an edge constraint constraints.createConstraint(physics_id_1, physics_id_2, constraint_type, edge_position_x, edge_position_y, edge_position_z, edge_angle_x, edge_angle_y, edge_angle_z)
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)
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)