-- PhysicsProj
-- Use this function to perform your initial setup
function setup()
w1 = physics.body(EDGE, vec2(0,0), vec2(WIDTH, 0))
w2 = physics.body(EDGE, vec2(0,0), vec2(0, WIDTH))
w3 = physics.body(EDGE, vec2(WIDTH, 0), vec2(WIDTH, HEIGHT))
garbagey = 40
linedestroy = true
onlyonce = true
balls={}
balls= CreateBall()
end
function CreateBall()
local p = physics.body(CIRCLE,50)
p.restitution = .8
p.linearVelocity = vec2(math.random(100,400), math.random(100,400))
p.x = math.random(60,250)
p.y = math.random(400,600)
p.color = color(math.random(0,255), math.random(0,255), math.random(0,255),100)
return p
end
function touched(t)
if t.state == BEGAN and not tw then
if CurrentTouch.x < otherx1 and CurrentTouch.x > otherx2 then
print("Success!")
gingerx = CurrentTouch.x
gingery = CurrentTouch.y
else
if CurrentTouch.x > otherx1 or CurrentTouch.x < otherx2 then
print("Error!")
ellipse(balls.x, balls.y, 200)
end
end
end
end
function draw()
background(220)
-- This sets a dark background color
fill(255,255,0)
fill (balls.color)
otherx1 = balls.x + 45
otherx2 = balls.x - 45
if CurrentTouch.x > otherx1 or CurrentTouch.x < otherx2 then
print("Test.")
end
if CurrentTouch.x < otherx1 or CurrentTouch.x > otherx2 then
balls.x = CurrentTouch.x
balls.y = CurrentTouch.y
ellipse(balls.x, balls.y, 100)
end
strokeWidth(5)
end
This is one of my feeble attempts to use a physics object. Literally, the ONLY thing I am trying to achieve, is that when you touch the ball, it moves where you drag it. If you don’t touch in the premise of it, it won’t move. That’s it. I am scared I am so bad at this.
godhelpusall
In serious terms, I dunno. I can’t get the physics object to not use gravity without doing balls.x/y = CurrentTouch.x/y in draw, but that breaks EVERYTHING! The only reason I use physics instead of a normal ol’ ball is so I can use collision/overlapping detection, which I intend to use later on. Help, please?