Jump to content

  • Log In with Google      Sign In   
  • Create Account

HitBox Question in XNA


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 JonathanCCC   Members   -  Reputation: 158

Like
0Likes
Like

Posted 11 November 2010 - 06:44 PM

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.

Sponsor:

#2 NightCreature83   Crossbones+   -  Reputation: 3033

Like
0Likes
Like

Posted 11 November 2010 - 09:20 PM

You want to actaully transform the boxx you just created to the position that is 1/2 the size of that box added on to the position of the player. I assume here that player postion is top left corner.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS