Hello, I need some basic help with physics. I want to do a kind of robot helicopter (just a circle that obey to physics laws and has thrust) I’m really newbie. I read the wiki, but didn’t find any help.
I already made this code that use physics, but without the physics api:
function setup()
x = CurrentTouch.x
y = CurrentTouch.y
inTouch = false
Velocidade_horizontal = 0
r = 30
a=0
watch ("Velocidade_inicial_vertical")
watch("Velocidade_vertical")
watch ("Velocidade_horizontal")
iparameter("Gravidade",0,100,50)
iparameter("Rastro",0,1,1)
iparameter("Parabola_Perfeita",0,1,0)
iparameter("Sensor_da_velocidade_vertical",0,30,12)
end
function draw()
if inTouch then
x = tx
y = ty
c = tc
a=0
background(0, 0, 0, 255)
else
G = Gravidade / 20
a=a+G
x = x + Velocidade_horizontal
y = y + Velocidade_inicial_vertical - a
Velocidade_vertical = Velocidade_inicial_vertical - a
z = Velocidade_vertical * Sensor_da_velocidade_vertical
if Rastro < 1 then
background(0, 0, 0, 255)
z = 255
end
if Parabola_Perfeita > 0 then
if y < CurrentTouch.y then
x = x - Velocidade_horizontal
y = y - Velocidade_inicial_vertical + a
Velocidade_vertical = Velocidade_inicial_vertical
end
end
if z < 0 then
z = -z
end
fill(z,255, z,255)
ellipse(x,y,r)
end
if y > HEIGHT - r then
Velocidade_inicial_vertical = - Velocidade_inicial_vertical + a
end
if y < r then
Velocidade_inicial_vertical = - Velocidade_inicial_vertical
a = - a
end
if x > WIDTH - r then
Velocidade_horizontal = - Velocidade_horizontal
end
if x < r then
Velocidade_horizontal = - Velocidade_horizontal
end
end
function touched(touch)
tx = touch.x
ty = touch.y
if touch.state == BEGAN then
inTouch = true
velocity = {}
end
if touch.state == MOVING then
table.insert(velocity,1,vec2(touch.deltaX,touch.deltaY))
end
if touch.state == ENDED then
Velocidade_horizontal = 0
Velocidade_inicial_vertical = 0
n = 0
for i = 1,10 do
if velocity[i] then
n = n + 1
Velocidade_horizontal = Velocidade_horizontal + velocity[i].x
Velocidade_inicial_vertical = Velocidade_inicial_vertical + velocity[i].y
end
end
if n >0 then
Velocidade_horizontal = Velocidade_horizontal / n
Velocidade_inicial_vertical = Velocidade_inicial_vertical / n
end
inTouch = false
end
end
It is based on this: https://bitbucket.org/TwoLivesLeft/codea/wiki/TouchTutorial
Here are my questions:
How to draw a circle (using physics api) on screen?
How to put a “force”(thrust) on the circle, and make the thrust rotate (I mean, change the direction of the thrust)?
Sorry for any english issue.