I am trying to raise a ball when I hold down on the screen and have it fall when I release, however I can’t make it smooth and at a gentle speed. My code is to fast and sudden. I am using physics and impulses to do this. Could someone help make this more smooth? Here is my code:
-- Use this function to perform your initial setup
function setup()
--ground=physics.body(EDGE,vec2(0,0),vec2(WIDTH,0))
fingers=0
box=physics.body(CIRCLE,50)
box.x=400
box.y=400
box.sleepingAllowed=false
physics.gravity(0,-100)
end
function touched(touch)
if(touch.state == BEGAN)then
fingers = fingers + 1
end
if(touch.state==ENDED)then
fingers = fingers - 1
end
if(fingers>0)then
box:applyForce(vec2(0,800))
end
end
function drawObject(obj)
ellipse(box.x,box.y,50)
end
-- This function gets called once every frame
function draw()
background(0,0,0)
drawObject(box)
end
-- Use this function to perform your initial setup
function setup()
--ground=physics.body(EDGE,vec2(0,0),vec2(WIDTH,0))
fingers=0
box=physics.body(CIRCLE,50)
box.x=400
box.y=400
box.sleepingAllowed=false
physics.gravity(0,-100)
end
function touched(touch)
if(touch.state == BEGAN)then
fingers = fingers + 1
end
if(touch.state==ENDED)then
fingers = fingers - 1
end
end
function drawObject(obj)
if(fingers>0)then
box:applyForce(vec2(0,100))
end
ellipse(box.x,box.y,50)
end
-- This function gets called once every frame
function draw()
background(0,0,0)
drawObject(box)
end
@austinmccoy Here’s something I pulled from one of my projects. Touch the screen for upward thrust. Move you finger left or right to move left or right.
displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT_ANY)
function setup()
vel=vec2(0,0)
b=physics.body(CIRCLE,15)
b.x=WIDTH/2-100
b.y=HEIGHT-50
end
function draw()
background(40, 40, 50)
sprite("Tyrian Remastered:Part H",b.x,b.y)
if flame then -- show lander flame
sprite("Tyrian Remastered:Flame 1",b.x,b.y-20,15,-30)
end
lv=b.linearVelocity
if up then
vel.y=vel.y+.5
b.linearVelocity=lv+vec2(vel.x,vel.y)
end
end
function touched(t)
if t.state==BEGAN or t.state==MOVING and lv~=nil then
up=true
flame=true
vel.x=vel.x+t.deltaX/10
end
if t.state==ENDED then
up=false
flame=false
vel=vec2(0,0)
end
end