Handling Character Animation & Movement?
Posted: Sun Aug 16, 2009 12:12 pm
Hey guys, I've been messing around with this little 2D RPG style project for ages now and I just can't seem to get it looking quite like I want.
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.
This worked fine for some time. Then I added a camera.
And of course the camera looked jerky because it's moving ~10.5 pixels per update. So I changed it a bit.
The camera could now follow the character at its own pace. This produced really jerky movement, as the character was only center screen half of the time.
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.
This looked really nice as far as scrolling, but since the character's speed was no longer based on animation, the animation would run on it's own time and be completely independent from where the character was (if the character was moving at all, the animation would be updating at a constant 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.
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.