Can anyone give me an explanation. What are WorldPoints and LocalPoints. I see two functions to use to convert from one to the other, but I’m not sure of their purpose. I don’t know what they are or how they’re used. Thanks in advance.

Each physics object has it’s own coordinate system, such that the bottom left of the object is 0,0. That object maybe be located in the physics “world” which has it’s own coordinate system. So if a square object sized 20 x 20 is located at 300,300 in the world, then the enter of the square is 10,10 in local coordinates, and it is 310,310 in world coordinates. So, for example, If there is a collision and you get the local coordinates of the collision, you may need to translate that to world coordinates to draw the effect of the collision.

I tried to write a simple program to try and visualize what you said. My program isn’t working how I expected it to, based on what you said. I was expecting the local points of the circles at collision to be 0,0 and the world points to be the values from the lower left corner of the screen. The circle centers, local point, are from the lower left corner and the world points are always about double the local point values. I tried changing the value of c1.x to cause collisions at different points, but the world points are always about double the local points. I guess I still don’t understand local and world points, or is my program wrong.

```
function setup()
print("Local and World Point example")
paused=false
c1 = physics.body(CIRCLE,50)
c1.x=300
c1.y=900
c1.gravityScale=.1
c2 = physics.body(CIRCLE,50)
c2.x=300
c2.y=600
c2.gravityScale=0
end
function collide(contact)
if contact.state == BEGAN then
l1=c1:getLocalPoint()
print("\
local c1 x,y",l1.x,l1.y)
w1=c1:getWorldPoint(vec2(l1.x,l1.y))
print("world c1 x,y",w1.x,w1.y)
l2=c2:getLocalPoint()
print("\
local c2 x,y",l2.x,l2.y)
w2=c2:getWorldPoint(vec2(l2.x,l2.y))
print("world c2 x,y",w2.x,w2.y)
paused=true
print("\
Program paused")
physics.pause()
end
end
function draw()
background(30, 30, 30, 25)
stroke(255)
strokeWidth(1)
noFill()
ellipse(c1.x,c1.y,100,100)
ellipse(c2.x,c2.y,100,100)
if paused==true then -- draw local point center of circle
fill(255,0,0)
ellipse(l1.x,l1.y,2,2)
ellipse(l2.x,l2.y,2,2)
end
end
```

both getLocalPoint and getWorldPoint take a vec2 as an argument, that might be giving you odd results.

Thanks @John

I was missing the vec2 for the getLocalPoint. Sometimes, no matter how hard you look for why code doesn’t work, you can’t see it. Then when someone points it out, it’s like why couldn’t I see that. This one gives the results I was expecting based on what @Vega mentioned. The world points now correspond to the center of the circles when they collide.

```
function setup()
print("Local and World Point example")
paused=false
c1 = physics.body(CIRCLE,50)
c1.x=300
c1.y=900
c1.gravityScale=.1
c2 = physics.body(CIRCLE,50)
c2.x=300
c2.y=600
c2.gravityScale=0
end
function collide(contact)
if contact.state == BEGAN then
l1=c1:getLocalPoint(vec2(c1.x,c1.y))
print("\
local c1 x,y",l1.x,l1.y)
w1=c1:getWorldPoint(vec2(l1.x,l1.y))
print("world c1 x,y",w1.x,w1.y)
l2=c2:getLocalPoint(vec2(c2.x,c2.y))
print("\
local c2 x,y",l2.x,l2.y)
w2=c2:getWorldPoint(vec2(l2.x,l2.y))
print("world c2 x,y",w2.x,w2.y)
paused=true
print("\
Program paused")
physics.pause()
end
end
function draw()
background(30, 30, 30, 25)
stroke(255)
strokeWidth(1)
noFill()
ellipse(c1.x,c1.y,100,100)
ellipse(c2.x,c2.y,100,100)
if paused==true then -- draw world point centers of circle
fill(255,0,0)
ellipse(w1.x,w1.y,2,2)
ellipse(w2.x,w2.y,2,2)
end
end
```