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[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);[/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.
Thanks for reading.
Could you please help me?
No replies to this topic