Re: Trig and the infamous "45 degree angle bug"

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Tue, 5 May 1998, Robert B Pilkington wrote:

> The ship is going too fast. (sqrt((xv*xv)+(yv*yv))=speed) I need to slow
> it down. I get the angle that the ship is trying to go, then slow that
> down. (Set it to max, which is less than what it is trying to go) Then, I
> convert the angle it wants to go to X and Y velocities. Basically, I need
> to convert to polar form (velocity and angle), but don't need velocity,
> already have it, then I have the angle the ship is *TRYING* to go. By
> slowing the velocity to the max, then converting polar form (velocity and
> angle) to rectangular form (X and Y), should fix this bug......

I remember this one... and I recall that my last suggestion didn't work
(once you went full speed in one direction, you couldn't turn),
so let me try something else.

speed = sqrt((xv*xv)+(yv*yv))
if speed > maxspeed then
  xv = xv * maxspeed / speed
  yv = yv * maxspeed / speed
end if

Basically the normalizing the vector idea, only it's scaled to maxspeed
instead of 1.  This should preserve the angle that the ship is trying to
go, but without converting it from rectangular to polar and back again.

Later,
--
                   _____         _____        _____
    ________      /\    \       /\    \      /\    \
   /   \    \    /  \____\     /  \____\    /  \____\
  /  _  \____\  /   / ___/_   /   /____/   /   / ___/_
 /  / \  |____|/   / /\____\ /    \    \  /   / /\____\
 \  \_/ /    / \   \/ / ___/_\     \    \ \   \/ / ___/_
  \    /____/   \    / /\    \\/\   \    \ \    / /\    \
   \   \    \    \   \/  \____\  \   \    \ \   \/  \____\
    \   \    \    \      /    /   \   \____\ \      /    /
     \   \____\    \    /    /     \  /    /  \    /    /
      \  /    /     \  /    /       \/____/    \  /    /
       \/____/       \/____/xseal at harborside.com\/____/

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu