Archived

This topic is now archived and is closed to further replies.

NoEscom

sprite/ground detection?

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.








Share this post


Link to post
Share on other sites
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


Share this post


Link to post
Share on other sites