forums

TNT Basic Forums > Beyond Basic
Wyvern: stuff about your spacetest
< Last Thread     Next Thread >
Author
Thread        Post A Reply

04-13-2004 20:45

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Hey. I was looking at the spacetest code from the directory.

quote:
'If you can
'do it a better way as I am sure you probably can, please email me.
repeat
'reduce our velocity by 1/100th
chx=chx*0.99
chy=chy*0.99
'recalculate numb, our velocity.
numb=sqrt((chx)^2+(chy)^2)
'...and if numb is still not small enough...
until numb<speed{ship}


I don't know your email, so I'm using the forum.

Well, instead of doing this, you can work backwards, knowing the maximum speed you wish to limit the ship to. But instead, I'll make it simpler to explain:

a/b=(a*cos(angle))/(b*cos(angle))=(a*sin(angle))/(b*sin(angle))

Right?
Well, a*cos(angle) is the horizontal distance of the point.
So....

numb/maxVelocity=x/newX=y/newY

So, to find newX and newY, we can say...
newX=x*maxVelocity/numb
newY=y*maxVelocity/numb

04-14-2004 18:52

Posted by:
-wyvern

Location:
Bedroom

Find more posts by -wyvern

I dont understand... Ach, I'm bad at maths. I'll give it a shot and if it works I'll tell you. It's going to be one of those 'simple when you know how' things...

04-14-2004 19:10

Posted by:
-wyvern

Location:
Bedroom

Find more posts by -wyvern

No joy. Can you put the numbers in terms of the variables in the program?

04-14-2004 19:42

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

If you replace the repeat loop (lines 260-267?) with the following code, it should work:

quote:

numb=sqrt((chx)^2+(chy)^2)
if numb>speed[ship]
chx=chx*speed[ship]/numb
chy=chy*speed[ship]/numb
end if



When I was testing to make sure it worked, the speed seemed to go up to 10.4 for the cruiser–0.4 past the max speed–then stop. The weird thing is, the x and y velocities were the same as when numb was 10. That shouldn't make a noticeable difference anyway.

04-14-2004 21:58

Posted by:
-wyvern

Location:
Bedroom

Find more posts by -wyvern

Okay, it's working now. I'll try and figure it out it and write it into the test later - I've got an unpleasant amount of work to do for the moment. Thanks very much.

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.