1. Trig and the infamous "45 degree angle bug"

I think I have the bug solved, but I can't come up with the actual
math... So I can't find out for sure.



       |\
       |  \  Total speed
    YV |    \
       |      \
       |________\ <--- Need this angle

          XV
So I need some *FAST* functions to find the angle given the x and y
lengths (XV and YV), and a function to return XV and YV given speed and
angle.

Why do I need this stuff, exactly? I know the ship is going too fast, so
I need to slow it down. The old method just checks to see if the XV is
too fast, slow it down if necessary, then check the YV. This works fine
unless XV and YV aren't more than the maximum speed, but the hypertense
of the triangle with XV and YV is too fast, then the ship goes to fast.
If XV and YV are maxed out, you go at a 45 degree angle, and faster than
you should. This is a common bug with many games, but in some, it doesn't
matter. With the new weapons I am trying to put into Vector, the bug is
causing you to run into your own shots and blow yourself up if you are
going faster than you should. Here is what I am trying to do:

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......

Hope I explained this well enough. These routines need to be fast in
order to actually use, but if they work, I can at least find out if the
algorithm works. I can't test it unless I have them.... If you see
something wrong with my math, and can still fix this bug, then I'd like
to hear it.

Thanks

_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]

new topic     » topic index » view message » categorize

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

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 message » categorize

3. Re: Trig and the infamous "45 degree angle 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.

It works! 100% perfect. Well, at least to printf()'s default 8 decimal
precision places.. :)

_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]

new topic     » goto parent     » topic index » view message » categorize

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

[Asteroids clones]
There are two ways that you can approach these, either making your game what
you consider to be the most playable, or the most realistic. I assume you have
opted for (1) as barring relativity there is no maximum speed in space.

> So I need some *FAST* functions to find the angle given the x and y
>  lengths (XV and YV), and a function to return XV and YV given speed and
>  angle.

The angle you wanted can be calculated using atan(YV/XV). If Euphoria's atan()
is too slow, most of the PI programmes have one, and you could get Pete or
some other asm genius to port one for you.

>  Why do I need this stuff, exactly? I know the ship is going too fast, so
>  I need to slow it down. The old method just checks to see if the XV is
..
>  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

Pete's technique for this looks dead right to me.

NB I have some code for simulating gravity. It uses the proper physical
formulas and values, so if any of you space-gamers are not into physics, send
me a mail and you'll be saved the slog.

Daniel

new topic     » goto parent     » topic index » view message » categorize

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

>[Asteroids clones]
>There are two ways that you can approach these, either making your
>game what you consider to be the most playable, or the most realistic. I
>assume you have opted for (1) as barring relativity there is no maximum
>speed in space.

Playable and realistic. I'll just use excuses for anything that doesn't
make sense... ;)

[No max speed in space]
Dampening field and other technical jargon you hear from Star Trek,
otherwise, it would be too easy to go too fast and crash into
something... It's a safety feature! ;) (This is a joke, AFAIK, a
dampening field slows you down, but I'm not sure, in that case, a
dampening field would slow you down without thrusters on, but that
doesn't happen in my game. I'm sure there is some way to explain the top
speed effect... And it's always fun to yell out "technobabble" and not
know what you are talking about and make sense to those who aren't paying
attention. :)

>The angle you wanted can be calculated using atan(YV/XV). If
>Euphoria's atan() is too slow, most of the PI programmes have
>one, and you could get Pete or some other asm genius to port one for
you.

I'll need the angle so the AI can test in the direction it is going for
any rocks in it's way and do something if there is. I've gotten a couple
requests for the rocks to do the same to the enemy fighters as they do to
you... :)

>Pete's technique for this looks dead right to me.

To at least 8 decimal places. With 16, you can see it have an error of
0.00000000000001 (or something like that) in either direction. I consider
that accurate enough. :)

_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu