function init() body = FindBody("practicetarget") trigger = FindTrigger("practice", true) light = FindLight() joint = FindJoint() mi, ma = GetJointLimits(joint) SetJointMotorTarget(joint, mi, 2) RemoveTag(body, "practicetarget") active = false armed = false SetLightEnabled(light, false) end function tick(dt) if IsPointInTrigger(trigger, GetPlayerCameraTransform().pos) then local current = FindBody("practicetarget", true) if current==0 and not active and math.random() < 0.01 then active = true armed = false SetJointMotorTarget(joint, ma, 2, 100) SetTag(body, "practicetarget") SetLightEnabled(light, true) end if active then local movement = GetJointMovement(joint) if movement > ma-0.1 then SetJointMotor(joint, 0, 0) armed = true end if armed and movement < mi+0.1 then active = false armed = false RemoveTag(body, "practicetarget") SetJointMotorTarget(joint, mi, 2) SetLightEnabled(light, false) end end else RemoveTag(body, "practicetarget") active = false armed = false SetJointMotorTarget(joint, mi, 2) SetLightEnabled(light, false) end end