views:

104

answers:

2

Hi,

Im making a game in xna where a tank has to move over a landscape. I need to be able find the bottom of the tank when it is rotated so I can make it move up and down as the player goes over the landscape.

for example if i have a sprite at with its top left corner at 400,300 and i rotate it around its center by 45 degrees around its center, how do i find the new locations of the bottom track.

Thanks

A: 

Not 100% clear on exactly what it is you are trying to do. You mention a sprite, which is 2D, but your description is in 3D terms. If you are doing a 2D side view, then you can't tell the tank is rotated 45 degrees. If you are doing a 2D top-down view, then you shouldn't really care where the bottom of the tred is.

In any case, two suggestions. If you are die-hard on tracking rotated pixels, then read this article: 2D collision with Transformed Pixels from the creators.xna.com site. However I would recommend tracking vectors. Use two vectors to represent the track locations, and then use Vector2.Transform to rotate them with the tank. You could then use the vectors to check to see if the tracks have hit something, what angle they are at, ect.

Languard
A: 

Thanks for the reply Langaurd.

I have looked at the article link before but didnt understand how it works.

Im making a 2d side scrolling game. As the player moves left and right, the tank has to also tilt to follow the contour of the terrain.

I have two vectors that store the back bottom of the track and one that stores the front bottom of the track.

I have tried

Vector2 backBottom = new Vector2(5, 25);
Vector2 frontBottom = new Vector2(5, 32);

backBottom = Vector2.Transform(backBottom+position, Matrix.CreateRotationZ(angle));
frontBottom = Vector2.Transform(frontBottom+position, Matrix.CreateRotationZ(angle));

but that gave me some strange values