Collision check

Hello GameDev team,

I would like to ask why this code is not working properly, what is difference from the code in video:

        if (CheckCollisionRecs(prop.GetCollisionRec(knigth.getWorldPos()), knigth.GetCollisionRec()))
        {
            collision = true;
        }

            if(collision)
            {
                knigth.undoMovement();
            }

Tha character simply stop moving or better say “world” is not moving when collision (set to false outside while loop) is true but animation is working.

Could you shortly explain why is that? Is it not the same code just with 1 additional variable and if statement? I know that it’s not cleaner code as in video but I am curious why it’s not working.

Thanks a lot.
Lukas

Hi Lukas,

Just to clarify, does the collision not occur?

Hi Tuomo_T,

Yes, after collision is occurring, the character stuck on the position. The animation is working in both directions and the character just standing, like when I hit “left button” he is animating to the left but not moving and vice versa.

Thanks
Lukas.

I’ve fixed it. I didnt spend any time about thinking to this “problem” since I’ve created the post. Of course I had to set collision back to false after for loop hehe…The next lectures and daily programming making experiences and this is the proof. :slight_smile:

The post can be SOLVED.

Thank you,
Lukas

You’re very welcome! I was just going to ask for more code cause your sample would not have been enough to solve the problem on my end.

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

Privacy & Terms