I've been thinking about how to go about giving each player the ability to move, animate, and be followed by a scrolling camera in my world.
NOTE: Most of the following is pseudo-code to represent the methods used in their simplest forms.
The first thing I had set up involved the character's movement being dependent on its animation.
Code: Select all
case UP:
character.y -= walkHeight / totalFrames;
Code: Select all
case UP:
character.y -= walkHeight / totalFrames;
camera.y -= character.y;
Code: Select all
case UP:
character.y -= tileHeight / totalFrames;
Code: Select all
if( camera.y > character.y - (camera.h/2 + character.h/2) ){
camera.y -= speed;
If I slowed the camera down the animation would look okay, as well as a smooth camera, but I didn't really like the camera following so far behind.
So I changed character movement to be no longer based on animation.
Code: Select all
case UP:
character.y -= speed;
Code: Select all
camera.speed = charToFollow.speed;
if( camera.y > character.y - (camera.h/2 + character.h/2) ){
camera.y -= camera.speed;
The issue was mostly due to my tilebased movement, where the character would stop moving at the center of the next tile unless it found input still in which case it would carry on. When moving more than one tile execution went something like: character.walking is set to false, animation is stopped, input is checked, character walking is set to true, animation is started again. This constant start/stop cause jerky animation.
At this point I decide let's just forget tile-based movement and let the player go where he pleases.
This works beautifully, everything is smooth and constant until you let up on the key. But now I have to rewrite the entire collision detection portion of the engine due to no longer using tile-based movement (keep track of which tile character is on, check a single tile in front of him in the direction of travel). With the added possibility of standing on four tiles at a time, I have to check every tile's collision in the direction of travel that collide with the character's width or height. While this wouldn't be all that hard to change, it would also mess up my object interaction system because it wouldn't know which object you're trying to interact with if you're colliding with two at once.
Anyways.. I've just been playing around with a bunch of ideas and this project isn't anything real important, just something to spend some time on. I'd like to know how you guys have handled or would handle movement, animation, scrolling, and collision in an RPG-style environment in comparison to what I've tried.
Constructive criticism is always welcome, so feel free to tell me how horrifying my attempts have been.