Limit Physics Body Movement Speed and Direction
-
Description
When an object is controlled by the physics engine, you can set limits on how it moves using this block:
Let’s go through the 5 input parameters:
Speed Limit
The first input is the maximum speed the object is allowed to move:
- If the object is moving at a slower speed, then it will not be affected by this limit;
- If the object is moving 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 move too fast. When an object moves too fast, it might jump to the other side of an obstacle, so the physics engine will not correctly treat it as being blocked by the obstacle.
If you do not want to set a speed limit, you can leave this input empty or specify a very large number.
Allowed Directions
The next 3 inputs are used to specify whether the object is allowed to move in each of the 3 directions. For example, if we set X to “No”, then the object’s movement along the X axis will always be 0. As a result, it will always stay at the same X position.
Object Name
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.
Demo
In this program, we place a box on a plane, then apply an impulse to push it.
When there is no limit, the box flies to the right forward direction.
If we set a speed limit of 111 or 11, the box is much slower.
If we set the X direction to “No”, then the box would only move along the Z-axis and Y-axis.
If all 3 directions are not allowed, then the box will stay where it is.
You can play with this project yourself here:
https://play.creaticode.com/projects/d41dbd54ff5e9cbed1f59c61