瀏覽代碼

Merge pull request #14 from paweljarosz/master

Replaced recreation of joints with setting new properties.
Björn Ritzl 4 年之前
父節點
當前提交
cac213ba54
共有 2 個文件被更改,包括 5 次插入8 次删除
  1. 1 1
      examples/physics/hinge_joint/hinge_joint.md
  2. 4 7
      examples/physics/hinge_joint/hinge_joint.script

+ 1 - 1
examples/physics/hinge_joint/hinge_joint.md

@@ -1,5 +1,5 @@
 ---
 ---
-title: Joint physics
+title: Hinge joint physics
 brief: This example shows a simple setup with a dynamic body physics object and two dynamic wheel physics object joined together with a joint of type "hinge". The hinge joint can simulate an axle or a pin on which other object is rotating in respect to the base. The example shows how to create, destroy and change properties of the joints.
 brief: This example shows a simple setup with a dynamic body physics object and two dynamic wheel physics object joined together with a joint of type "hinge". The hinge joint can simulate an axle or a pin on which other object is rotating in respect to the base. The example shows how to create, destroy and change properties of the joints.
 scripts: hinge_joint.script
 scripts: hinge_joint.script
 ---
 ---

+ 4 - 7
examples/physics/hinge_joint/hinge_joint.script

@@ -6,7 +6,7 @@ local center_anchor = vmath.vector3(0, 0, 0)
 local frontwheel_anchor = vmath.vector3(60, -60, 0)
 local frontwheel_anchor = vmath.vector3(60, -60, 0)
 local backwheel_anchor = vmath.vector3(-60, -60, 0)
 local backwheel_anchor = vmath.vector3(-60, -60, 0)
 
 
-local hinge_props = { enable_motor = true, enable_limit = false, max_motor_torque = 60, motor_speed = 5 * 2 * math.pi}
+local hinge_props = { enable_motor = true, enable_limit = false, max_motor_torque = 3000, motor_speed = 1 * 2 * math.pi}
 
 
 function init(self)
 function init(self)
 	msg.post(".", "acquire_input_focus") -- <2>
 	msg.post(".", "acquire_input_focus") -- <2>
@@ -23,10 +23,8 @@ function on_input(self, action_id, action)
 		else  -- <9>
 		else  -- <9>
 			hinge_props.motor_speed = -5 * 2 * math.pi -- <10>
 			hinge_props.motor_speed = -5 * 2 * math.pi -- <10>
 		end
 		end
-		physics.destroy_joint(frontwheel, "frontwheel") -- <11>
-		physics.destroy_joint(backwheel, "backwheel")
-		physics.create_joint(physics.JOINT_TYPE_HINGE, frontwheel, "frontwheel", center_anchor, body, frontwheel_anchor, hinge_props) -- <12>
-		physics.create_joint(physics.JOINT_TYPE_HINGE, backwheel, "backwheel", center_anchor, body, backwheel_anchor, hinge_props)
+		physics.set_joint_properties(frontwheel, "frontwheel", hinge_props) -- <11>
+		physics.set_joint_properties(backwheel, "backwheel", hinge_props)
 	end
 	end
 end
 end
 
 
@@ -41,6 +39,5 @@ end
 8. Set the motor_speed property to 5 revolutions per second in clockwise direction.
 8. Set the motor_speed property to 5 revolutions per second in clockwise direction.
 9. If the direction flag is false, we are going backward.
 9. If the direction flag is false, we are going backward.
 10. Set the motor_speed property to 5 revolutions per second in counter-clockwise direction.
 10. Set the motor_speed property to 5 revolutions per second in counter-clockwise direction.
-11. Destroy a current joint for frontwheel and backwheel.
-12. Recreate the joints with new properties.
+11. Set the new properties with changed speed for the joints.
 --]]
 --]]