# Total noob help me with gravity

I am a very new to programming etc could any one help me to make a sprite start off near the top and fall to the bottom using gravity(not the iPads accelerometer) here’s my code I know I’ve done so much wrong…

`````` -- football

-- Use this function to perform your initial setup
function setup()
print("touch to kick")
end

-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(255, 255, 255, 0)

-- This sets the line thickness
strokeWidth(5)

physics.gravity(spx,spy)
sprite("Documents:football",spx,spy,256,204)

-- Do your drawing here

end
``````

Thanks for any help and would be nice to get linked to a tutorial on the basics of lua…

Check out these tutorials, they are rather good. http://coolcodea.wordpress.com/

look at the physics example in the included codea project as well.

If you are completly new to programming I’d suggest learning some programming basics first. google lua programming tutorials and forget the codea librarys until you are comfortable with loops and conditionals.

Thanks for the link and I have some basic experience in java

Does this help any. I don’t have a football image, so I used a raindrop.

``````
supportedOrientations(LANDSCAPE_ANY)

function setup()
parameter.integer("xstrength",100,400)
parameter.integer("ystrength",200,600)
p1=physics.body(CIRCLE,10)
p1.x=10
p1.y=10
p1.gravityScale=0
end

function draw()
background(255, 255, 255, 0)
fill(255,0,0)
sprite("Small World:Raindrop Soft",p1.x,p1.y)
if p1.y<=10 then
p1.gravityScale=0
p1.linearVelocity=vec2(0,0)
text("Tap screen to kick",WIDTH/2,HEIGHT-100)
text("Use parameters to change x,y strength",WIDTH/2,HEIGHT-150)
end
end

function touched(t)
if t.state==BEGAN then
p1.linearVelocity=vec2(xstrength,ystrength)
p1.gravityScale=1
p1.x=10
p1.y=10
end
end

``````

Thanks for the code it has helped me a bit but what does p1.y and p1.x mean. Also how could I set it so I don’t choose the x strength and y strength so it’s just full y strength and little x strength.

p1 (just a name I picked) is the physics object and p1.x and p1.y are variables to keep track of the physics.body x and y values. The physics.body is what gets affected by gravity (and a bunch of other conditions) and you use it’s x and y values to control the position of the sprite. If you don’t want to change the x and y strength, just change p1.linearVelocity=vec2(xstrength,ystrength) to what values you want. For instance p1.linearVelocity = vec2(200,400) or whatever values work for what you want. You can then remove the parameter.integer lines of code.