Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / help with asteroids movement code

Author
Message
demons breath
20
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 31st Jul 2004 16:37 Edited at: 2nd Aug 2004 04:41
I've attached the code that I have a problem with. I am using the balla# method of movement (from the pong tutorial), but it doesnt seem to do anything. However, the ball starts moving when I press up and slows when I let it go but if I press the left or right arrow key then it goes off the bottom of the screen really quickly.

Please help - I'm not very good with DarkBASIC and I probably did the thrust thing wrong but I just tried to figure it out.

Thanks



Am I the only one here who's really confused?
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 3rd Aug 2004 05:26
Okay, I think you have two different things going on at once here...

The first is the thrust value, which relates to the up and down keys. When you press up the thrust increases, until it reaches 10 when it stops because it's limited. However, when you release the key you are decrementing it again, until it reaches the point of zero when it STILL GOES more negative, but more slowly.

Next we have your left & Right arrows. This is a real mess. Firstly you're Y rotating which I do not understanding, because you're using X & Z for the position. Then you are changing the angle by 5 degrees each time, such that I cannot predict what the result will be (my head don't carry that many decimal points) and then are using that new angle to predict the new location of the object on each pass. Since it is constantly rotating while the thrust value is changing, I'm not surprised you're seeing these results.

Sadly, I cannot determine how to help however, since my head doesn't quite warp that way. I think you should probably re-read the tutorial again and double check your coding befor proceeding, or maybe someone else can fathom what's going on...
S.

Any truly great code should be indisguishable from magic.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 3rd Aug 2004 06:06 Edited at: 3rd Aug 2004 06:08
Okay, I thought about it some more and feel that these lines be should be changed;

Not...
if upkey()=0 then thrust#=thrust#-0.05
if thrust#<0 then thrust#=thrust#-0.01

But...
if upkey()=0 then thrust#=thrust#-0.05
if thrust#<0 then thrust#=thrust#+0.05

Or better on the last line;
if thrust#<0 then thrust#=0.0

That should stop that moving down immediately. So long as thrust keeps going negative with you not pressing a key, you're going to moving very fast in no time at all.

Good luck.
S.

[Edit] Still don't get the yrotate thing, but this should stop the symptom.

Any truly great code should be indisguishable from magic.
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 4th Aug 2004 08:29
You want to make sure that thrust is limited to between 0 and 10, instead of subtracting 0.01 if it's below 0

Is this any better:



It still isn't perfect asteroids code since the angle still effects the direction mid flight. If you wanted to get over this you would have to store seperate thrust values for the x and z directions, and adjust them both when the up key is pressed.

Login to post a reply

Server time is: 2024-09-22 19:23:02
Your offset time is: 2024-09-22 19:23:02