# Gravity help

I cannot figure out why the gravity is not working, yet I have it already implemented
Help appreciated

code

``````
function setup()
physics.gravity(vec2(0,-1000))

touch=1

b1 = physics.body(EDGE,vec2(0,0),vec2(WIDTH,0))
b2 = physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
b3 = physics.body(EDGE,vec2(WIDTH,0),vec2(WIDTH,HEIGHT))
b4 = physics.body(EDGE,vec2(0,HEIGHT),vec2(WIDTH,HEIGHT))

block=physics.body(CIRCLE,40)
block.x=WIDTH/2
block.y=40
blockx=block.x
blocky=block.y

end
function draw()
background(255, 255, 255, 255)
block.linearVelocity=(vec2(CurrentTouch.x - block.x, CurrentTouch.y - block.y))
if touch> WIDTH/2 then
blockx=blockx+4
end
blockx=block.x
blocky=block.y
sprite("Documents:hoopx2",0,5,700,1200)

end

``````

Anytime you do anything with a physics object, you shouldn’t alter its velocity directly as you’re doing with blockx. You should only use linearVelocity.

I got rid of all the access code from failed attempts

Since I don’t have access to your sprites, it’s hard to tell what’s happening. Instead of using CurrentTouch, try to use the touched() function. The calculation with CurrentTouch isn’t allowing the physics object (block) to act the way it should.

@Conor_R12 Here’s your code using the function touched().

``````
function setup()
b1 = physics.body(EDGE,vec2(0,0),vec2(WIDTH,0))
b2 = physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
b3 = physics.body(EDGE,vec2(WIDTH,0),vec2(WIDTH,HEIGHT))
b4 = physics.body(EDGE,vec2(0,HEIGHT),vec2(WIDTH,HEIGHT))

block=physics.body(CIRCLE,40)
block.x=WIDTH/2
block.y=800
block.restitution=.8
end

function draw()
background(255, 255, 255, 255)
sprite("Documents:hoopx2",0,5,700,1200)
end

function touched(t)
if t.state==BEGAN then
block.linearVelocity=vec2(t.x-block.x,t.y-block.y)
end
end

``````

Try using

``````block:applyForce(vec2(CurrentTouch.x - block.x, CurrentTouch.y - block.y))
``````

``````block.linearVelocity = vec2(CurrentTouch.x - block.x, CurrentTouch.y - block.y)