Jump to content

  • Log In with Google      Sign In   
  • Create Account


Problem:calculate a position by angle


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
No replies to this topic

#1 elad1223   Members   -  Reputation: 101

Like
0Likes
Like

Posted 29 November 2012 - 03:02 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).
[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. Posted Image
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. Posted Image
Thanks for reading.
Could you please help me? Posted Image

Sponsor:



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