Sign in to follow this  
Maxine

Player pushing a block problem

Recommended Posts

Maxine    122
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.

[CODE]
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();
}
[/CODE]

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 [b]rectangular 4 directional box-pushing? (Diagonal is not an option).[/b]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this