Difference Between Local and World Coordinates in Planck.js?

Understanding the distinction between local and world coordinates is essential for accurately positioning, moving, and managing collisions between rigid bodies in planck.js. While world coordinates define an absolute position within the entire 2D physics simulation canvas, local coordinates are relative strictly to a specific body’s origin and rotation. Mastering how these two coordinate systems interact allows developers to precisely apply forces, attach joints, and translate screen positions into simulation physics.


(Wait, the prompt said “Don’t create any horizontal rules in the article.” Let me remove that immediately and rewrite without it.)

Difference Between Local and World Coordinates in Planck.js?

Understanding the distinction between local and world coordinates is essential for accurately positioning, moving, and managing collisions between rigid bodies in planck.js. While world coordinates define an absolute position within the entire 2D physics simulation canvas, local coordinates are relative strictly to a specific body’s origin and rotation. Mastering how these two coordinate systems interact allows developers to precisely apply forces, attach joints, and translate screen positions into simulation physics.

What are World Coordinates?

World coordinates represent the global frame of reference for your entire physics simulation. Think of the world space as the master map or the stage where all physics bodies exist.

What are Local Coordinates?

Local coordinates represent a frame of reference that is tied directly to an individual rigid body. Imagine standing on a moving ship; your position relative to the ship’s deck stays the same, even though the ship is moving across the ocean.

Key Differences at a Glance

Converting Between Systems in Planck.js

Planck.js provides built-in methods on the Body object to seamlessly convert vectors and points between these two systems.

Transforming Local to World

If you have a point relative to the body and need to know where it sits on the global map, use:

Transforming World to Local

If you have a global coordinate (like a mouse click position) and need to know where that is relative to the body’s center, use: