Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Finding an angle relative to current 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
3 replies to this topic

#1 Rexxaw(Forgrim's mate)   Members   -  Reputation: 121

Like
0Likes
Like

Posted 26 April 2011 - 11:57 PM

Righty, so;

I have a current rotation value of an object stored as radians, i am looking for a way to find the object's right and left, in a radian value.
This will allow me to move(strafe) left and right relative to it's heading.

So current angle = #
angle right = # (function here... )

Ive tried converting to degrees and then back again, but its making it overly complex i think, and doesn't sort the problem of angle being relative.
Anyone familiar with this problem?

Sponsor:

#2 Rexxaw(Forgrim's mate)   Members   -  Reputation: 121

Like
1Likes
Like

Posted 27 April 2011 - 12:31 AM

Heres my solution



if (Keyboard.GetState().IsKeyDown(Keys.A))
{


speed = 0.35f;
// degrees = 270.0f;
degrees = MathHelper.ToDegrees(pRot);
degrees -= 90;
pRotStrafe = MathHelper.ToRadians(degrees);


pVlx = (float)Math.Cos(pRotStrafe) * speed;
pVly = (float)Math.Sin(pRotStrafe) * speed;

pPos -= new Vector2(pVlx, pVly);



}

if (Keyboard.GetState().IsKeyDown(Keys.D))
{
speed = 0.35f;
degrees = MathHelper.ToDegrees(pRot);
degrees += 90;
pRotStrafe = MathHelper.ToRadians(degrees);

pVrx = (float)Math.Cos(pRotStrafe) * speed;
pVry = (float)Math.Sin(pRotStrafe) * speed;
pPos -= new Vector2(pVrx, pVry);

}


Strikes me as a lot of computation but it does work.

To alleviate all the questions i badger the boards with i can at least post solutions as i find them. :)

#3 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 27 April 2011 - 01:50 PM

Typically you'd do this using vector math rather than angles/trig. For example, given a vector (x, y), the perpendicular vectors are (-y, x) and (y, -x) (which is basically what you're computing here, but in a less straightforward way).

#4 mozie   GDNet+   -  Reputation: 194

Like
0Likes
Like

Posted 28 April 2011 - 07:06 AM

You can cut out the conversion here, since Pi/2 (radians) = 90 (degrees).

degrees = MathHelper.ToDegrees(pRot);
degrees -= 90;
pRotStrafe = MathHelper.ToRadians(degrees);

would become...

pRotStrafe = pRot - Pi/2;







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