Limit Physics Body Rotation Speed and Direction
CreatiCode last edited by
When an object is controlled by the physics engine, you can set limits on how it rotates using this block:
Let’s go through the 5 input parameters:
The first input is the maximum speed the object is allowed to rotate in:
- If the object is rotating at a slower speed, then it will not be affected by this limit;
- If the object is rotating at a faster speed, then its speed will be reduced to this value.
In other words, you can use this block to make sure an object does not rotate too fast.
If you do not want to set a speed limit, you can leave this input empty or specify a very large number.
The next 3 inputs are used to specify whether the object is allowed to rotate around each of the 3 axes. For example, if we set X to “No”, then the object will not rotate around the X axis.
If you leave the name input empty, the currently selected sprite object will be given the speed limit. If you input an object’s name, then that object will be given the speed limit.
In this program, we place a box on a plane, then apply an impulse to push it.
When there is no limit, the box will rotate around both the X-axis and Y-axis.
If we set a rotation speed limit of 10, the box will rotate much slower.
If we set the X direction to “No”, then the box would only rotate around the Y-axis.
If we set the Y direction to “No” as well, then the box would not rotate at all.
You can play with this project here: