Jump to content
  • Advertisement
Sign in to follow this  
Maxine

Player pushing a block problem

This topic is 2301 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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!