Sign in to follow this  
JonathanCCC

HitBox Question in XNA

Recommended Posts

hi all,

I have a quick question regarding hitboxes.

currently I have a player ship and I create my collision detection on it by this simple method:

Vector2 playerposition;
playerposition = new Vector2(playerx, playery);

Rectangle playerRectangle =
new Rectangle((int)playerposition.X, (int)playerposition.Y,
player.Width, player.Height);


Since in my game the enemy fire lots of bullets, I wanted to make the hit box twice as small. I thought the following might accomplish this:

Rectangle playerRectangle =
new Rectangle((int)playerposition.X, (int)playerposition.Y,
player.Width / 2, player.Height / 2);

Which does great for the right hand side of the ship, but the left is still "pixel perfect", I understand why, since I am halfing the X, only the right hand side gains. Yes i'm a beginner, and i'm unsure how I half both sides and create a small hitbox in the middle of my ship texture.

any help appriciated, thanks.

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