Log In  

Cart #11073 | 2015-06-02 | Code ▽ | Embed ▽ | No License

Howdy folks, this is a quick demo of a method I use when making tile-based games to make sure characters don't get stuck on corners. Try using the arrow keys to go through the hole and you should see how it feels.

The basic idea is to save the last movement for both axes and to use that to correct the player's movement when they collide with something. While it feels pretty natural, there are two cases where it falls down:

  1. The Long Slide - because the slide state never times out, you can go right while pushing up indefinitely (or whatever). This seems unnatural when you do it, but it's not really something I've seen players do intentionally.

  2. Overshooting - Try overshooting the gap in this demo and you'll see that you head off to the right. Ideally you'd gravitate towards the hole, and while there are lots of ways to arrange that I'm not familiar with any that are as easy to implement as this (but if you have ideas please tell me!). In practice I find people tend to undershoot more than overshoot, and that the visual feedback from overshooting allows for easy correction in a way getting stuck doesn't.

Anyway, hope this helps someone.

P#11074 2015-06-02 11:07 ( Edited 2015-06-03 20:02)

Take a look at how I handled this in Muncher (in the function called move_character) https://www.lexaloffle.com/bbs/?tid=1903

I round the current sprite's center position to find which cell it is mostly in, then use the keyboard controls to offset that by +/-1 in x/y and then move the sprite towards that new cell. This makes the collision detection with walls and such super easy and lets you bend around the corners.

It is not the same as Pac-Man, but it feels similar. Specifically, in Pac-Man you can actually go faster around the corners than the ghosts can. I recommend reading more here in the Pac-Man Dossier http://home.comcast.net/~jpittman2/pacman/pacmandossier.html

In your case, since you are allowing free roaming (unlike mine, which pulls you onto the grid) it might be more like the original Zelda did it. It has been a while since I looked at that, but I seem to recall that each step that Link takes ends up snapping you to a quarter of a tile in the direction orthogonal to the direction you move in, so that it feels like you can roam freely, but you have several pixels of auto-alignment to help you get through narrow gaps. If you watch closely it looks like he turns around the corner a bit each time you make a 90 degree turn.

P#11089 2015-06-03 01:20 ( Edited 2015-06-03 05:20)

I been having trouble figuring out how to draw a map (room)
:(
Can someone do a cartridge that does nothing else but draw a map.
So I don't get lost in code for player controls, etc...
Thank you so much in advance :)

P#11095 2015-06-03 16:02 ( Edited 2015-06-03 20:02)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 17:25:02 | 0.010s | Q:17