Physics Tools Extension"Physics Tools Extension" provides some additional blocks for working with the Box2D environment. It includes tools for precision trajectory calculations and collision detection on a curved path.
The purpose of the "Physics Tools Extension" is to make it easy to perform routine calculations. Some example problems include:
- You want an actor to jump exactly 6 tiles across and 4 tiles high. What should you set the velocity and angle to?
- You want an enemy actor to fire at your player using a curved path. Will it be able to, or is there an obstacle in the way?
- You want an enemy actor to jump at your player. How much force should it use to jump?
- You want to draw an arc that shows what path a projectile may follow.
DownloadThe extension can be downloaded
here (.zip),
here (.tar.gz), or from
my site (.zip or .tar.gz).
A sample project file can be downloaded
here or from
my site.
Old Releases are available from my
Archives PagePlease see:
How to Install and Update an Extension.
Quick ReferenceDocumentation is provided below. The documentation can also be found on
my site.
Returns direction of motion
Push the actor with enough force to clear the specified distance in pixels (e.g. jump)
Push the actor with enough force to clear the specified distance in tiles (e.g. jump)
Returns the first actor on the trajectory from x, y at given velocities. The time interval (see illustration below) will specify the section of the arc to search for a collision within.
Returns a list of all actors on the trajectory from x, y at given velocities. The time interval will specify the section of the arc to search for a collision within.
Returns the projected x or y position of the actor n seconds into the future.
Returns the velocity with specified horizontal and vertical speeds
Returns the projected x or y coordinate of a moving body from starting x or y coordinate and velocity n seconds into the future
Returns the x or y speed necessary to launch a body from (x1,y1) to (x2,y2) at an angle of n degrees.
Note: "angle" is used to determine the highest point the projectile will reach before it descends. The image below illustrates the effect "angle" has on the path. A rectangular box is drawn, the width of which is the horizontal distance between the projectile and target. The angle between the two diagonals determines the height.
To form a trajectory that is as high as is far, select an angle of 45 degrees.
Launch an actor to a specified point. The "angle" parameter behaves as explained above.
Returns true if the "angle" parameter, as used above, is sufficient.
In some cases, the "angle" parameter may be too low for the computed trajectory height to reach the intended target. In this case, two errors may be seen if a launch is executed: "PhysicsTools.launchVelocity: Negative discriminant." or "PhysicsTools.doLaunch: Angle insufficient to reach target height."
This block allows the developer to check for this condition before attempting a launch.
Returns the horizontal speed (x) or vertical speed (y) component of velocity in a given direction.
Returns the angle formed by the diagonal connecting (x1,y1) and (x2,y2).
Returns the first actor on an arc from (x1,y1) to (x2,y2) at specified velocity.
Returns a list of all actors on an arc from (x1,y1) to (x2,y2) at specified velocity.
Returns the angle of motion to hit a target at (x2,y2) at a specified velocity.
Version History2015-10-24: (Beta Release) Added 10 blocks
Beta release notes: These ten blocks solve the problem I had in my own game (that motivated this extension) and some problems I remember from browsing the forums over the past few months. I can add more if requested.
Please note that this is the beta release. There may be a few bugs that slipped through the cracks. Please let me know if you find any
One block you will not see is a simple "launch from point A to point B". The reason is that more information is needed to determine a trajectory: either the length of time the projectile will take to complete its flight, or the highest point the projectile will reach. I chose to implement the latter, in the form of the "angle" parameter, since it should be easier to visualize.
"angle" essentially determines the aspect ratio of a box the arc path will reside in. (e.g. a 45-degree angle gives a 1:1 ratio of distance horizontal to distance vertical).
2015-10-26: (Beta Release 2) Added two blocks: ("x/y-speed with given velocity" and "aspect angle")
2015-10-29: (Beta Release 3) Two updates:
1. Added one block: ("all actors on arc")
2. Converted * 10 and / 10 constants to proper functions (toPixelUnits and toPhysicalUnits)
2015-11-24: (Beta Release 4) Added three blocks (requested by Liberado)
1. First actor on arc from (x1,y1) to (x2,y2) at angle A
2. All actors on arc from (x1,y1) to (x2,y2) at angle A
3. Angle of velocity to hit a target from (x1,y1) to (x2,y2) with given velocity V