physics_joint_enable_motor

Enables (or disables) the motor of a joint that permit this behaviour.

Syntax:

physics_joint_enable_motor(joint, motor)


Argument Description
joint The joint that you wish to enable or disable the motor on
motor Whether you wish to turn the motor on (true) or off (false)


Returns: N/A


Description

When you have a joint with a motor (prismatic or revolute), you may want to be able to switch the motor on or off depending on variables and conditions within the game. For this, you need to have stored the index of the joint previously in a variable and then you can switch the motor on or off by using this function and setting the "motor" argument to true or false.


Example:

var t_fix = physics_fixture_create();
physics_fixture_set_circle_shape(t_fix, sprite_get_width(sprite_index) / 2);
var o_id=instance_create_layer(x+300, y, "Instances", obj_Door);
physics_fixture_bind(t_fix, id);
physics_fixture_bind(t_fix, o_id);
perma_joint = physics_joint_revolute_create(id, o_id, x+25, y, -90, 90, 1, 10, 2, 0, 0);
physics_joint_enable(perma_joint, 1);
physics_fixture_delete(t_fix);

The above code creates and defines a new fixture and then creates an instance of "obj_Door", binding the created fixture to the two instances. They are then joined by a revolute joint with no motor and the angles limited to a +/- 90 degree swing, and we store the joint index in the variable "perma_joint". We then switch the motor on using this variable, before finally deleting the fixture from memory as it is no longer needed.


Back: Joints
next: physics_joint_get_value
© Copyright YoYo Games Ltd. 2018 All Rights Reserved