-------------------------------------------------------------------------------- -- Function......... : updateMotor -- Author........... : -- Description...... : -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- function Car.updateMotor ( ) -------------------------------------------------------------------------------- local o = this.getObject ( ) if ( this.bGoFront ( ) ) then this.nMotorSpeed ( 2500 ) this.nMotorPower ( 150000 ) elseif ( this.bGoBack ( ) ) then local vx, vy, vz = dynamics.getLinearVelocity ( o, object.kLocalSpace ) if ( vz > -0.5 ) then this.nMotorSpeed ( -1000 ) this.nMotorPower ( 50000 ) else this.nMotorSpeed ( 0 )-- -1500 ) this.nMotorPower ( 0 )--150000 ) dynamics.setAngularVelocity ( this.hWheelBL ( ), 0, 0, 0, object.kGlobalSpace ) dynamics.setAngularVelocity ( this.hWheelBR ( ), 0, 0, 0, object.kGlobalSpace ) dynamics.setAngularVelocity ( this.hWheelFL ( ), 0, 0, 0, object.kGlobalSpace ) dynamics.setAngularVelocity ( this.hWheelFR ( ), 0, 0, 0, object.kGlobalSpace ) end else this.nMotorSpeed ( 0 ) this.nMotorPower ( 0 ) end local oSpeed = dynamics.getLinearSpeed ( o ) local speed = this.nMotorSpeed ( ) local power = this.nMotorPower ( ) local bFactor = 0.5 - math.min ( 40, oSpeed ) / 40 * 0.5 local lFactor local rFactor if ( this.bTurnLeft ( ) ) then lFactor = 0.5 rFactor = 1.5 elseif ( this.bTurnRight ( ) ) then lFactor = 1.5 rFactor = 0.5 else lFactor = 1.0 rFactor = 1.0 bFactor = 0.5 end dynamics.setHinge2JointAxis2MotorSpeedLimit ( o, "Wheel1", speed * 1.0 ) dynamics.setHinge2JointAxis2MotorSpeedLimit ( o, "Wheel2", speed * 1.0 ) dynamics.setHinge2JointAxis2MotorSpeedLimit ( o, "Wheel3", speed * lFactor ) dynamics.setHinge2JointAxis2MotorSpeedLimit ( o, "Wheel4", speed * rFactor ) dynamics.setHinge2JointAxis2MotorAcceleration ( o, "Wheel1", power * bFactor ) dynamics.setHinge2JointAxis2MotorAcceleration ( o, "Wheel2", power * bFactor ) dynamics.setHinge2JointAxis2MotorAcceleration ( o, "Wheel3", power * lFactor ) dynamics.setHinge2JointAxis2MotorAcceleration ( o, "Wheel4", power * rFactor ) -------------------------------------------------------------------------------- end --------------------------------------------------------------------------------