# problem:Calculate an poisition by angle.

Page 1 of 1

## 0 Replies - 3519 Views - Last Post: 29 November 2012 - 01:20 AM

Reputation: 0
• Posts: 1
• Joined: 29-November 12

# problem:Calculate an poisition by angle.

Posted 29 November 2012 - 01:20 AM

Hello all,
I build a "worms" game.
In the start of the develop,I did that the player would flate the terrain below him.
As the game develops I want the player to have the ability to move.
So I calculate the angle I need to rotate him relatively to the terrain.
(I got an array with all the terrain heights and the player's width is 40).

Vector2 positon2=new Vector2(players[i].Position.X+30,terrainContour[(int)players[i].Position.X+30]);
Vector2 position=new Vector2(players[i].Position.X+10,terrainContour[(int)players[i].Position.X+10]);
Vector2 distance = position - positon2;
players[i].BaseAngle =MathHelper.PiOver2+(float)Math.Atan2(distance.X,-distance.Y);
players[i].WeaponAngle = MathHelper.ToDegrees(players[i].BaseAngle+MathHelper.PiOver2);

Till now all good the player is rotate relatively to the terrain and the weapon also. />
But now I want to place the weapon in the middle of the player.

Before I rotated all the position of the weapon relateively to the player position was
new Vector2(20,-10)

But now I need to treat the BaseAngle too. I thought a matrix should do it so I did this matrix:
Vector2 WeaponRot = Vector2.Transform(new Vector2(0, 0), Matrix.CreateRotationZ(MathHelper.ToRadians(player.BaseAngle))*Matrix.CreateTranslation(new Vector3(xpos + 20, ypos - 10, 0))
and used the WeaponRot as the position.

Unfortunately, It didnt work as some of the rotations works and some not. />