1. Re: Trig and the infamous
On Tue, 5 May 1998, Robert B Pilkington wrote:
> The algorithm Pete sent me works perfectly, never goes over 5, never
> drops under 5. (Unless you turn enough to slow you down, in any case, it
> works :) I have no idea what a "normalize the vector idea" is, but it
> works, so I'm happy.
I'm using "normalize" as in Physics when calculating the "unit vector".
The velocity vector can be broken down into two parts, the speed and the
direction. The speed is the length of the vector ( sqrt(xv*xv + yv*yv) ).
The direction is given by either an angle or a unit vector. The unit
vector is the velocity vector scaled down to length=1. Or, the angle (as
Wally suggested) is arctan(yv/xv). To get a unit vector from an angle,
you set xv=cos(angle) and yv=sin(angle). Since the unit vector has
length=1, you can multiply it by your maximum speed to get a velocity
vector that has the same direction as the original, but the length will be
maxspeed.
(stealing your diagram)
> |\
> | \ Total speed = sqrt(XV*XV + YV*YV)
> YV | \
> | \
> |________\ <--- Need this angle
>
> XV
this is the unit vector:
> |\
> | \ 1
> YV/speed | \
> | \
> |________\
>
> XV/speed
then multiply the unit vector by maxspeed:
> |\
> | \ maxspeed
>(YV/speed)| \
> *maxspeed| \
> |________\
>
> (XV/speed)*maxspeed
and presto! a new vector in the same direction with the right length.
and using angles:
> |\
> | \ 1
>sin(angle)| \
> | \
> |________\<--- angle=arctan(YV/XV)
>
> cos(angle)
then,
> |\
> | \ maxspeed
>sin(angle)| \
> *maxspeed| \
> |________\<--- angle=arctan(YV/XV)
>
> cos(angle)*maxspeed
> >I think it matters in all games. It's just that most games developers
> >think that game players for the most part are rather stupid.... well
> >maybe we are but I don't like my intelegence insulted so I think it is
> >good when a programmer is concerned with this issue
all the more reason to get a good education.
well this is long enough... I hope this explains things a little (pictures
help).
--
_____ _____ _____
________ /\ \ /\ \ /\ \
/ \ \ / \____\ / \____\ / \____\
/ _ \____\ / / ___/_ / /____/ / / ___/_
/ / \ |____|/ / /\____\ / \ \ / / /\____\
\ \_/ / / \ \/ / ___/_\ \ \ \ \/ / ___/_
\ /____/ \ / /\ \\/\ \ \ \ / /\ \
\ \ \ \ \/ \____\ \ \ \ \ \/ \____\
\ \ \ \ / / \ \____\ \ / /
\ \____\ \ / / \ / / \ / /
\ / / \ / / \/____/ \ / /
\/____/ \/____/xseal at harborside.com\/____/
http://www.harborside.com/home/x/xseal/euphoria/