Jump to content
  • Advertisement
Sign in to follow this  
Maxine

Player pushing a block problem

This topic is 2448 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I've created a box class. The box can be pushed in 4 directions: Vertically and horizontally as soon as the player collides with it. My problem is that the three sides I test first works, but which ever side i try to calculate last; One of the previous sides already qualifies and the last side gets ignored.


if (OnCol(target))
{
if (target.GetX() <= position.X + 1 && target.GetY() >= colBox.Top && target.GetY() <= colBox.Bottom)
position.X += target.GetSpeedX();
else if (target.GetX() >= position.X - 1 && target.GetY() >= colBox.Top && target.GetY() <= colBox.Bottom)
position.X -= target.GetSpeedX();
else if (target.GetY() <= position.Y + 1)
position.Y += target.GetSpeedY();
else if (target.GetY() >= position.Y - 1)
position.Y -= target.GetSpeedY();
target.BackTrack();
}


Now this current example is just in the middle of my current attempt to get it to work. Can anyone give me a good way to handle rectangular 4 directional box-pushing? (Diagonal is not an option).

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!