sprite/ground detection?
How does one generally implement sprite/ground detection? I can''t get it to work properly The problem is, when my sprite falls of a platform and i let it collide with the platform again during the fall, the sprite is moved back onto the platform. Ofcourse i don''t want this. Some source to clarify the problem:
if (sprite->GetSpeedY() > 0) {
// if we are not on the ground, we must be falling or jumping
tile_y = (sprite->GetYPos() + TILE_SIZE) / TILE_SIZE;
if (((m_tile_map[tile_y][sprite->GetXPos() / TILE_SIZE])->GetType() == MAP_GROUND) //
((m_tile_map[tile_y][(sprite->GetXPos() + TILE_SIZE) / TILE_SIZE])->GetType() == MAP_GROUND)) {
// if sprite is falling, put it on the ground tile
sprite->SetYPos((tile_y * TILE_SIZE) - TILE_SIZE);
sprite->SetSpeedY(0);
break;
}
}
Anyone has an idea how to improve it?
Give the sprite some forward movement. In other words you
know the dimensions of the object you are on now move the
sprite beyond that. Here it is in 2d.
Your sprite box (It''s dimension)
******** <- Your sprite
* *
* *
* *
********
*************
*
*
***************** <- The floor
Now set the min X of your sprite to the max X of the floor
+1 or whatever. Now you have cleared the floor.
know the dimensions of the object you are on now move the
sprite beyond that. Here it is in 2d.
Your sprite box (It''s dimension)
******** <- Your sprite
* *
* *
* *
********
*************
*
*
***************** <- The floor
Now set the min X of your sprite to the max X of the floor
+1 or whatever. Now you have cleared the floor.
Oops! The diagram didn''t work it stripped the spaces out. Ok
imagine that @ is a space...
@@**********<-Your sprite
@@*@@@@@@@@*
@@*@@@@@@@@*
@@*@@@@@@@@*
@@**********
**************<-Floor
@@@@@@@@@@@@@*
@@@@@@@@@@@@@*
@@@@@@@@@@@@@***************<-Floor
How the heck do you include spaces!!! This looks so weird
imagine that @ is a space...
@@**********<-Your sprite
@@*@@@@@@@@*
@@*@@@@@@@@*
@@*@@@@@@@@*
@@**********
**************<-Floor
@@@@@@@@@@@@@*
@@@@@@@@@@@@@*
@@@@@@@@@@@@@***************<-Floor
How the heck do you include spaces!!! This looks so weird
My Geekcode: "GCS d s: a14 C++$ P+(++) L+ E-- W+++$ K- w++(+++) O---- M-- Y-- PGP- t XR- tv+ b++ DI+(+++) D- G e* h!"Decode my geekcode!Geekcode.com
Visit our web site:Asylum Entertainment
Visit our web site:Asylum Entertainment
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement