# Linear Impulse

Hey Guys, I’m really new at Codea and try to use it for a school project.
So my Idea is, to have an actor ( a physical (dynamic) actor ( like a sphere ) ) in the middle of the screen at the begining. Then, if you tap the screen once one the right side, the actor jumps in a bow a bit to the right side and falls down, like in flappy birds. And if you press the left side of the screen once the actor should jump in a bow to the left side. So you can jump around in the scene. But i’ve got no idea how to realize it I read something about linar impulse on the actor, but i don’t know, how to give my actor physical behavours.
Can you please help me with this, is there a good tutorial for my problem? would be nice
Thanks

Here’s something to give you an idea. Tap the left or right side of the screen.

``````function setup()
b=physics.body(CIRCLE,50)
b.x=WIDTH/2
b.y=HEIGHT/2
b.gravityScale=0
end

function draw()
background(40, 40, 50)
fill(255)
ellipse(b.x,b.y,100)
end

function touched(t)
if t.state==BEGAN then
if t.x<WIDTH/2 then
b.linearVelocity=vec2(-20,0)
else
b.linearVelocity=vec2(20,0)
end
end
end
``````

There’s a lot of ways to do what you want, but without knowing what else you’re going to do I can’t tell you more than what I showed you above.

Here’s a quick mod that includes some fake friction.

``````function setup()
b=physics.body(CIRCLE,50)
b.x=WIDTH/2
b.y=HEIGHT/2
b.gravityScale=0
end

function draw()
b.linearVelocity = b.linearVelocity*0.99
background(40, 40, 50)
fill(255)
ellipse(b.x,b.y,100)
end

function touched(t)
if t.state==BEGAN then
if t.x<WIDTH/2 then
b.linearVelocity=b.linearVelocity + vec2(-50,0)
else
b.linearVelocity=b.linearVelocity + vec2(50,0)
end
end
end
``````

Actually, you don’t need fake friction. linearDamping can be used to slow the object down. The higher the value, the faster it slows.

``````function setup()
b=physics.body(CIRCLE,50)
b.x=WIDTH/2
b.y=HEIGHT/2
b.gravityScale=0
b.linearDamping=1
end

function draw()
background(40, 40, 50)
fill(255)
ellipse(b.x,b.y,100)
end

function touched(t)
if t.state==BEGAN then
if t.x<WIDTH/2 then
b.linearVelocity=b.linearVelocity + vec2(-50,0)
else
b.linearVelocity=b.linearVelocity + vec2(50,0)
end
end
end
``````

yes, i imagined there would be a way, though i didnt see it in the physics writeup. i had some point but i don’t know what it was …