Physics Short Cutt

In the subject of aniamating things with gravity, velocity, friction, amd collision/rebound, is there things built into lua that can already do these things for me and do I have to re-write the laws of phyics?

It’s built in. Look at the physics example provided with Codea

Ok, I’ll have a look.

.@Goatboy76 It doesn’t take a lot of code to create realistic simulations with the physics engine.

``````
supportedOrientations(PORTRAIT)
displayMode(FULLSCREEN)

function setup()
c1 = physics.body(CIRCLE,0)
c1.x = 400
c1.y = 1000
c1.type = STATIC
c2 = physics.body(CIRCLE,25)
c2.x = 200
c2.y = 900
c3 = physics.body(CIRCLE, 25)
c3.x = 500
c3.y = 950
c4 = physics.body(CIRCLE, 25)
c4.x = 300
c4.y = 850
p1=physics.body(POLYGON,vec2(-10,25),vec2(-10,-25),vec2(10,-25),vec2(10,25))
p1.x=400
p1.y=850
joint1 = physics.joint(REVOLUTE,c1,c2,c1.position)
joint2 = physics.joint(REVOLUTE, c2, c3,vec2(c2.x,c2.y))
joint3 = physics.joint(REVOLUTE, c3, c4,vec2(c3.x,c3.y))
joint4 = physics.joint(REVOLUTE, c4, p1,vec2(c4.x,c4.y))
end

function draw()
background(40, 40, 50)
fill(255)
strokeWidth(2)
line(c1.x,c1.y,c2.x,c2.y)
line(c2.x,c2.y,c3.x,c3.y)
line(c3.x,c3.y,c4.x,c4.y)
line(c4.x,c4.y,p1.x,p1.y)
ellipse(c1.x,c1.y,8)
ellipse(c2.x,c2.y,8)
ellipse(c3.x,c3.y,8)
ellipse(c4.x,c4.y,8)
translate(p1.x,p1.y)
rotate(p1.angle)
points = p1.points
for j = 1,#points do
a = points[j]
b = points[(j % #points)+1]
line(a.x, a.y, b.x, b.y)
end
end

``````

I’ve written a couple of tutorials on physics, starting here

http://coolcodea.wordpress.com/2013/03/21/applying-gravity/