# Problem:calculate a position by angle

This topic is 1882 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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).
[source lang="csharp"]Vector2 positon2=new Vector2(players.Position.X+30,terrainContour[(int)players.Position.X+30]);
Vector2 position=new Vector2(players.Position.X+10,terrainContour[(int)players.Position.X+10]);
Vector2 distance = position - positon2;
players.BaseAngle =MathHelper.PiOver2+(float)Math.Atan2(distance.X,-distance.Y);
players.WeaponAngle = MathHelper.ToDegrees(players.BaseAngle+MathHelper.PiOver2);[/source]
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
[source lang="csharp"] new Vector2(20,-10)[/source]
But now I need to treat the BaseAngle too. I thought a matrix should do it so I did this matrix:
[source lang="csharp"]Vector2 WeaponRot = Vector2.Transform(new Vector2(0, 0), Matrix.CreateRotationZ(MathHelper.ToRadians(player.BaseAngle))*
Matrix.CreateTranslation(new Vector3(xpos + 20, ypos - 10, 0)));[/source]

and used the WeaponRot as the position.
Unfortunately, It didnt work as some of the rotations works and some not.