Need help to start with physics.

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.

Jeomanmg, from what I see it think it will be easier to not use the physics API.

To draw a circle do

stroke(255,255,255,255)
strokeWidth(3)
fill(255,0,0,255)
elliipse(300,300,50)

To make the circle move, just keep track of its x,y coordinates in a variable and move that variable as you need it.

If you really need physics, take a look at the physics lab example. Test1 draws a circle that bounces around as you drag it

Thanks for reply, Ruilov!
I need the physics api because I want to drag and simulate inertia.
I’ve tried to isolate the circle from test 1, but it didn’t worked:


function createCircle(x,y,r)
    local circle = physics.body(CIRCLE, r)
    circle.interpolate = true
    circle.x = x
    circle.y = y
    circle.restitution = 0.25
    circle.sleepingAllowed = false
debugDraw:addBody(circle)
    return circle
end
    function setup()
    createCircle(WIDTH/2 + 50, 110, 30)
 
end

function draw ()
    
end

function touched(touch)

end

Well, i’m newbie, I don’t know what i did. :-s
It says that something is wrong on “debugDraw:addBody(circle)” but when i remove it nothing happens.

@Jeomanmg if you wish to experiment with physics it is probably a good idea to duplicate the entire physics lab project (hold the icon down in the project browser and select ‘Duplicate’) as you will likely need classes and functions contained on other tabs in that project.

Or have a look at these threads for help with rolling your own physics:

http://twolivesleft.com/Codea/Talk/discussion/comment/5052

http://twolivesleft.com/Codea/Talk/discussion/547

http://twolivesleft.com/Codea/Talk/discussion/comment/5237

Jeomanmg, as Blanchot mentioned duplicate the entire thing, or at least copy the contents of the debugDraw tab on the physics lab example. That’s where the debugDraw:addBody method is defined.

@Blanchot @ruilov Thanks for the tip, I’ve duplicated the file and removed useless stuff. Now, I’m trying to figure it out how it works.