Re: Trig and the infamous
Hello
>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.
Do you mean to check the actual speed and return that value?
I've added a few lines of code into vector.ex that I think fixed the
problem (the same idea that I mailed you). I've realized that the
percent multiplyer is very important. If it is too small you can go
over the max. If it is too large you can't reach the max. The only
value that is perfect is .9090909. I have no idea why it's such a weird
repeating number and no doubt .9090909090909090909 would be even better
but with all the rounding errors .9090909 is all that is neccesary to
reach exactly 5 eventually. If you want the exact (tested) code then
here it is (this also has 2 ways to show the speed on the screen so you
know (exactly) how fast your going at any given time):
my code goes right after these lines:
player[XV]= ......
player[YV]= ......
-- Lewis stuff
if player[XV] * player[XV] + player[YV] * player[YV] >
player_top_speed * player_top_speed then
player[XV] = player[XV] * .9090909 -- if you change this
player[YV] = player[YV] * .9090909 -- don't forget it.
end if
position(1,7)
puts(1,"speed: ")
-- speed show 1
--puts(1,repeat(X,2*sqrt(abs(player[XV] *
--player[XV] + player[YV] * player[YV]))))
-- speed show 2
print(1,sprt(abs(player[XV] * player[XV] +
player[YV] * player[YV])))
puts(1," ") --to erase incorrect end characters
-- end Lewis stuff
there's only one small problem with this: no matter what you change
player_top_speed to, your speed will never get over 5. I don't know how
to explain this unless my code is conflicting with some of yours.
If this gives you errors it's just miss copying on my part probably so
just play with it to get it to work
> |\
> | \ Total speed
> YV | \
> | \
> |________\ <--- Need this angle
>
> XV
^
|
Nice diagram :)
I thought the angle was what ever you plugged into the
rotate function.
>Why do I need this stuff, exactly? I know the ship is going too fast,
>so I need to slow it down.
So if you had the code to take care of the speed stuff you wouldn't
really need to know the angle? or would you?
>unless XV and YV aren't more than the maximum speed, but the
hypertense...
That's "hypotenuse" I think. It doesn't have an "r" in it
>you should. This is a common bug with many games, but in some, it
doesn't
>matter.
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
>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 think you're making this harder than it has to be, but if your idea
runs faster than mine, go for it.
Another thing: you probably will want to use this algorithm on all
moving objects in the game eventually so my code will need to be
modified and most likely put into a function or something.
Well, I hope this works,
Lewis Townsend
LewisArt
Keroltarr at hotmail.com
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
|
Not Categorized, Please Help
|
|