From physics body to touch chords and back again?

I am making a game, but have run into an issue. I want to be able to buck up the character, but if you let go I wan it to fall. I also need to know how to revise this code to keep the character a physics body at all times so it will not phase through walls. Good luck and thanks for taking a crack at it!

function touched(t)                         -- if C is touched then pick up (not a physocs body, but I want it to be one.)
       if t.x>c.x-30 and t.x<c.x+30 and t.y>c.y-30 and t.y<c.y+30 then
            c.x=t.x
            c.y=t.y     
       elseif t == false then -- if C is let go, fall and be a physics body 
        
        end

Someone please respond

Firstly, think of a better name for your physics body than c.

Keep it as a dynamic physics body, then, instead of setting its coordinates directly (a bad idea with dynamic physics body), try using applyForce with touch.deltaX and .deltaY

@yojimbo2000 thanks for the advice, but what is a dynamic physics body?

@Kai See the Codea reference under physics. That will answer your question plus give you a lot of info you can use later.

Thank you @dave1707 you are a huge help

@yojimbo2000 thanks for the advice, but I am not sure how to use this, I have read the reference but don’t understand how to combine these two segments to work together, please explaine more

@Kai create a physics body, a CIRCLE or a POLYGON. By default CIRCLE and POLYGON physics bodies are DYNAMIC, so you don’t need to change anything.

Then, experiment with applying force to it in the touched function.

myBody:applyForce(vec2(t.deltaX, t.deltaY))

@Kai Are you after something like this.

displayMode(FULLSCREEN)

function setup()
    e1=physics.body(EDGE,vec2(0,0),vec2(WIDTH,0))
    e2=physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
    e3=physics.body(EDGE,vec2(WIDTH,0),vec2(WIDTH,HEIGHT))
    e4=physics.body(EDGE,vec2(0,HEIGHT),vec2(WIDTH,HEIGHT))
    p1=physics.body(CIRCLE,50)
    p1.x=WIDTH/2
    p1.y=HEIGHT-50
    p1.restitution=.5
    physics.continuous=true
end

function draw()
    background(40, 40, 50)
    ellipse(p1.x,p1.y,100)
end

function touched(t)
    if t.state==MOVING then
        dx=t.deltaX
        dy=t.deltaY
        p1.linearVelocity=vec2(dx*50,dy*50)
    end
end

Yes @dave1707 but only to an exten. I want a character to move and when I let go, just react to gravity. Your example has helped but sadly Imstill need to experiment and hope to learn from this. Thank you!

@dave1707 I need a program as such that moves only at the location of my finger, not something that likes to go willy nilly

I also need something that doesn’t only go one way, so not just a linear velocity

Ok never mind I have tailored it to my needs. Thanks once again to @dave1707

@Kai Here’s what I changed.

displayMode(FULLSCREEN)

function setup()
    e1=physics.body(EDGE,vec2(0,0),vec2(WIDTH,0))
    e2=physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
    e3=physics.body(EDGE,vec2(WIDTH,0),vec2(WIDTH,HEIGHT))
    e4=physics.body(EDGE,vec2(0,HEIGHT),vec2(WIDTH,HEIGHT))
    p1=physics.body(CIRCLE,50)
    p1.x=WIDTH/2
    p1.y=HEIGHT-50
    p1.restitution=1
    physics.continuous=true
end

function draw()
    background(40, 40, 50)
    sprite("Planet Cute:Character Horn Girl",p1.x,p1.y)
end

function touched(t)
    if t.state==BEGAN or t.state==MOVING then
        if (t.x-p1.x)^2/50^2+(t.y-p1.y)^2/50^2 <= 1 then 
            p1.type=KINEMATIC
            p1.linearVelocity=vec2(0,0)
            p1.x=t.x
            p1.y=t.y
        end
    end
    if t.state==ENDED then
        p1.type=DYNAMIC
    end
end