The examples were unclear about this topic. I want to know how I can test if object 1 touches object 2 and how I can make change a Boolean if those two objects are touching.
This function works like the touch function:
function collide(c)
--All collisions between physics bodies happen here.
--Use c.state == BEGAN/c.state == MOVING/c.state == ENDED to collect the
--relevant data from collisions as shown in the reference in Codea.
if c.state == BEGAN then
print("Collided!")
end
end
It will print “Collided!” when two bodies hit.
What if I wanted to see if object 1 hit object 2 SPECIFICALLY rather than the floor?
@Paintcannon You can set an “info” field so that each object has a unique name. When a collision occurs, you check the “info” field and determine what you want to do based on that.
to amplify what dave said
--when you set up object A, also give it an id
A.info="A"
--then in the collide function
if bodyA.info=="A then --bodyA is A
elseif bodyB.info=="A then --bodyB is A
@Paintcannon — Or, use this is draw()
:
if bodyA:testOverlap(bodyB) then
--what is supposed to happen when they are touching
end
That is much simpler. Thank you.