We learned how to detect collisions thanks to the intersects
method provided by CGRect
, but in this way, the collision will be triggered as soon as the rabbit's ears touch the doors. Let's add another condition to the if
statement in detectCollisions
in order to take into account the rabbit's and door's frame position. Thus, the collision will only happen when the door reaches half the rabbit's frame. As shown in the following screenshot:
This challenge is very easy and I hope you were able to solve it. To perform this check, you just need to add the following condition to the if
statement:
&& (node.position.y - node.frame.height/2) <= self.rabbit.position.y
Keep this line in the code as we are going to use this condition in order to make the collisions more realistic.