Alternate collision detection method?

I wrote this when I first noticed that the box was travelling partially off the screen. Could this also work for the purpose of detecting the edges of our window in the axe game? The variable axe_h is the box height. If the box were irregularly shaped we could then use axe_w for the width of the box.

//Move the axe and reverse direction

        axe_y += direction;

        if(axe_y > (height - (axe_h / 2) ) || axe_y < (axe_h / 2 ))

        {

            direction = -direction;
1 Like

Your first bound looks correct. The second bound doesn’t need to be changed and can stay at axe_y < 0.

The reason for this is (and why the first bound works) is because the “origin” point of the axe is at the top-left corner of the drawn rectangle. So for detecting the edge at the top we only care if that origin point is reaching the top-edge of the screen, which is 0 in the y-axis.

Lol had I not been impatient and tried to figure it all out ahead of time and waited for the next video in the lesson I would have learned this :roll_eyes:. That’s what I get for rushing ahead. Thank you for letting me know, I really do appreciate it! Any and all feedback is, and always will be, appreciated.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms