I am writing a game on js (platformer). The player is presented in the form of a square, tile cards - also squares. On each frame, I determine if there is a player’s collision with any of the nearest tiles:
if (a.position.x <= b.position.x + b.width && a.position.x + a.width >= b.position.x && a.position.y <= b.position.y + b.height && a.height + a.position.y >= b.position.y) { console.log('Collision!'); } Thus, I determine if there is a collision at all, but how to determine if a collision occurred, which side exactly did the player encounter with the tile? Considering that this is a trivial task when developing games, there must be some kind of classical algorithm for solving it. What is he like?
facingRight = true;by default,facingRight = true;and then when you turn the player, change this variable - Alexey Shimansky