How do make a wall collider for platformer

im making like a 2d minecraft game thing and idk how to make wall colliding script
project: https://snap.berkeley.edu/project?user=danidanijr&project=project%20dcgsfhkghk
(you cant control the player, i need to add the script)

One way to do this is similar to how platformer scripts usually work in Scratch. You can check if a rectangular hitbox is intersecting with a non-empty grid space by getting the grid position of the four corners of the rectangle, then checking for every grid space in between the four corners using a nested for loop. Here is an illustration of this concept because whatever
grid-collision
To do collision with this, you can move the player in the x direction by the x velocity then check if it is touching something. If it is, then you move the player out of the wall, by moving the player in the opposite direction 1 block it is moving until it is not touching the level. Then you need to snap the X position of the edge to the grid. Then you do the same in the y direction with the y velocity. You can make it a bit faster by only checking the appropriate sides of the rectangle rather than the whole based on the direction it is moving, but in your game the character is a 1x1 square so there would be no difference whatsoever. Is that understandable?

Another way I can think of this is by doing raycasting. But that method would be more complex than the method I showed because you would need to implement raycasting.

I made a Minecraft pen-drawn game in scratch, if you go to this link and see inside, look at the collision script and assciated scripts and you can use that.
Here are the scripts:



Screenshot 2021-02-20 190439

Great!
This helps, I need similar physics for my entities in webcraft

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