Hi, sorry for a question that seems to me like it should be pretty simple but I cannot understand collisions. I am new to this an do would really appreciate it if someone were to help me out by telling me how to use them. Also can you provide examples? Thanks in advance 
Comments
Hi @Deretsuk
Here is a simple program showing a collision and how to get some info when a collision happens.
Thank you so much. This was so helpful
whats wrong with my code i want it to be able to make the sprites not overlapp
-- gravity with walls
-- Use this function to perform your initial setup
function setup()
print("rugby rules")
x = WIDTH/2
y = HEIGHT/2
xx = WIDTH/2
yy = HEIGHT/2
end
function draw()
-- This sets a dark background color
sprite("Documents:feild",WIDTH/2, HEIGHT/2, WIDTH, HEIGHT)
end
function isNotlapping()
local re1=x+20
local le1=x-20
local te1=y+20
local be1=y-20
local re2=xx+20
local le2=xx-20
local te2=yy+20
local be2=yy-20
if s2.re > s1.le or
s2.le > s1.re or
s2.be > s1.te or
s2.te < s1.be then
return false
end
end
function isOverlapping()
local re1=x+20
local le1=x-20
local te1=y+20
local be1 =y-20
local re2=xx+20
local le2=xx-20
local te2=yy+20
local be2=yy-20
if s2.re < s1.le or
s2.le < s1.re or
s2.be < s1.te or
s2.te > s1.be then
return true
end
end
my code got messted up
@minersack27 - please don't post comments in threads that are two years old, which have nothing to do with your problem. Start a new thread.
Also - put three ~ on the line before your code, and another three ~ on the line after your code, to format it nicely (you can edit your posts above to do this), otherwise nobody s going to be able to read your code at all
added the 3 ~'s before and after the code
@minersack27 Here's your code changed a little. I don't have the sprites you used so I picked some that's in Codea. The girl sprite can overlap the boy sprite, but the boy sprite can't overlap the girl sprite. A better way to do this is to use physics objects and let the physics code handle collisions.
@minersack27 Here's code using physics objects. It's a lot easier to let the physics engine do the collision detection. To move the characters, slide your finger around the screen starting on their side of the field. Each character can be moved on their own.