Discuss Scratch

kuswerdz
Scratcher
100+ posts

Issues with top-down 2D collision

I've been experimenting with tile scrolling lately. As you'll see in my project, my method is rather unconventional. I don't plan on changing it unless it's necessary, but I do have a problem with it: I can't seem to figure out how to make the player collide with the blocks. I'm trying to use little bars that follow the player to determine whether or not you can move, but it doesn't work very well. If anyone has a simple method I can use, I would greatly appreciate it.

The gray metal blocks are the ground, everything else should be collidable.

Link to the project:
PhiPhenomenon
Scratcher
500+ posts

Issues with top-down 2D collision

Here's my method to change Player X and Y:

Basically, it moves the tank on the screen forward how much it wants to move, simulating if it's in a wall or not. Then if it's not touching the level, it'll actually move forward and go back to the center of the screen. Not really the most elegant solution but it's the first I could think of.

Now one issue that you may notice is that when the tank goes to a corner and tries to turn, it's stuck.

If you look at the image above, you can see that the sides of the tank are inside the wall, which prevents it from moving out. You can fix this by creating a hitbox sprite that controls the tank movement and doesn't rotate. The tank is the cosmetic that gets put over the hitbox and rotates.
kuswerdz
Scratcher
100+ posts

Issues with top-down 2D collision

I was considering going with a simple approach like that, but the hitbox would not be able to free itself due to not being able to move if touching the blocks.

Powered by DjangoBB