if( (NewX % 512) < 64)
{
if( Map[ (NewX / 512) + ((NewY / 512) * 16) - 1] == 0) X = NewX; //Okey allowed
}
else if( NewX % 512 > 512 - 64)
{
if( Map[ (NewX / 512) + ((NewY / 512) * 16) + 1] == 0) X = NewX; //Okey allowed
}
else X = NewX;
Same for the Y. Seemed pretty good at first. But it doesn''t work, first of all, if you get near a corner of a tile it won''t work >_<. But otherwice it did supply me with the sliding effect.
Now I ask you: Have anyone got a good idea and maybe done it before?
Please help is needed!
Thanks in advance!
/MindWipe
Getting player to slide on X & Y near wall (tile based)
Okey. So I''m making this tile based game.
I''m using fixed point math (don''t ask me why) so in my virtual world ever tile is 512x512.
I want to be able to get the player to slide against the wall when he''s near it.
When I move I do the usual:
X += cos(a) * 128; (128, because I''m running at a low FPS count)
Y += sin(a) * 128;
The map is a 2d Array: int Map[16*16]; if a value is != 0, it''s solid and the player shouldn''t pass trough it.
I want to be able to have a "bigger" box around each tile, and get the player to slide on that. Say I don''t want the player to get any closer then 64 units from a wall.
This is how I began:
I''m not so sure I understand what you mean by slide. So "a" is your object''s angle, and it can face any direction? And when your object runs into a tile, you want to prevent it from getting stuck in any other directions it''s moving, and only stop the direction that hit the wall?
Well, for one thing, it shoudn''t be able to slide on corners, when the object is moving both axes toward the corner. It really should get stuck there, until they stop trying to move in both directions toward the wall.
If you really want it to slide anyway, you just have to figure out which axis is moving more based on your angle, and slide it while stopping the other. OR figure out which side of the tile the object is closer to (like if they ran into the bottom-right corner, check to see if they are more up on the tile, or more left), and slide that way.
Like I said, I may not understand your problem completely.
Well, for one thing, it shoudn''t be able to slide on corners, when the object is moving both axes toward the corner. It really should get stuck there, until they stop trying to move in both directions toward the wall.
If you really want it to slide anyway, you just have to figure out which axis is moving more based on your angle, and slide it while stopping the other. OR figure out which side of the tile the object is closer to (like if they ran into the bottom-right corner, check to see if they are more up on the tile, or more left), and slide that way.
Like I said, I may not understand your problem completely.
When doing the collision detection, project the player outside of the object setting its new position accordingly. The rest of the physics stuff remains the same. (if u want it to bounce off then project out by some distance)
ex: point x is in poly ABCDEF. Get the closest side of ABCDEF to x. Get the distance between the side and x (lets say it is AB). Add to x a vector from the closest point of AB to x (and multiply the vector by some value for bouncing - 1 = no bounce, 2 = bounce by 100% percent etc)
Death to the gaming industry! Long live games. /*ilici*/
ex: point x is in poly ABCDEF. Get the closest side of ABCDEF to x. Get the distance between the side and x (lets say it is AB). Add to x a vector from the closest point of AB to x (and multiply the vector by some value for bouncing - 1 = no bounce, 2 = bounce by 100% percent etc)
Death to the gaming industry! Long live games. /*ilici*/
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement