RPG style tilemap collision
by William Clark · in Torque Game Builder · 07/14/2006 (11:17 pm) · 0 replies
Hello everybody.
I'm trying to write a little bit of a tutorial for the RPG section on TDN, as well as work on my RPG project at the same time, and I've hit a bit of a hurdle.
I've got a tilemap up and running, with a little dude (well, an arrow) that you can move around in a top-down fashion, colliding with objects at will. Movement is handled like the side-scrolling shooter demo. Basically, pressing a button, say up, sets %littleDude.moveUp = true; and calls %littleDude.updateMovement();. That in turn sets his velocity and animation. When the button is released, the boolean is set to false, and updateMovement is called again. When he collides with an object, his progress in that direction is stopped by the clamp functionality, as it should be. However, if I move him "diagonally" (that is, hold two direction keys) past the object, he doesn't resume his former motion.
For example, if I move rightwards until I hit a box, then continue to hold right, and hold up to get around it, he will continue upwards forever, without resuming his rightward progress, even after getting around the box.
I understand why this is happening -- clamp simply sets the velocity in the direction of the collision to 0 -- but it's not what I want to have happen. Anyone's suggestions will be appreciated. Thanks.
Edit:
I guess I could just model my code after the platformer tutorial, and update the player's velocity each frame. I'll do this, but would prefer a more elegant solution if it exists.
Edit 2:
Ya, I'm just going to stick with that solution. It works pretty well. The only problem is the presence of friction (which doesn't want to turn off), but that's pretty minor.
I'm trying to write a little bit of a tutorial for the RPG section on TDN, as well as work on my RPG project at the same time, and I've hit a bit of a hurdle.
I've got a tilemap up and running, with a little dude (well, an arrow) that you can move around in a top-down fashion, colliding with objects at will. Movement is handled like the side-scrolling shooter demo. Basically, pressing a button, say up, sets %littleDude.moveUp = true; and calls %littleDude.updateMovement();. That in turn sets his velocity and animation. When the button is released, the boolean is set to false, and updateMovement is called again. When he collides with an object, his progress in that direction is stopped by the clamp functionality, as it should be. However, if I move him "diagonally" (that is, hold two direction keys) past the object, he doesn't resume his former motion.
For example, if I move rightwards until I hit a box, then continue to hold right, and hold up to get around it, he will continue upwards forever, without resuming his rightward progress, even after getting around the box.
I understand why this is happening -- clamp simply sets the velocity in the direction of the collision to 0 -- but it's not what I want to have happen. Anyone's suggestions will be appreciated. Thanks.
Edit:
I guess I could just model my code after the platformer tutorial, and update the player's velocity each frame. I'll do this, but would prefer a more elegant solution if it exists.
Edit 2:
Ya, I'm just going to stick with that solution. It works pretty well. The only problem is the presence of friction (which doesn't want to turn off), but that's pretty minor.
About the author