A long time ago I was trying to work out how the Thrust physics worked. I was fascinated by how the orb and the ship would spin around each other, with correct-looking inertia. So I created this Archimedes Basic version of how I thought it was working, and played around with some of the maths until it worked.
I've tidied this old program up with new comments, to try to better explain how I think the physics works. This program works well - so I guess this is how Thrust must be doing it. Keys are A,S for rotation, SHIFT+SPACE for Thrust/Pickup
![Image]()
I have since had a brief look through some of the disassemblies given in this thread, and I haven't studied them deeply, but I have found some comments about "angular momentum", which I don't think is the correct explanation (unless Jeremy Smith programmed this in a more complicated way than he needed to). Angular momentum is an emergent property of more basic laws of physics, i.e. newton's second law, tension, and newton's third laws, in this case. The above method in the BASIC program just considers the tractor beam as being inextensible, and calculates the necessary impulse within the tractor beam which is necessary to achieve this inextensibility, and considers the consequential momentum-changes this impulse imparts onto the orb and ship.
Code:
10REM >Thrust.txt 20ON ERROR MODE0:PRINT REPORT$;" at line ";ERL:END 30MODE 12 40rotation_speed%=8 50gravity=-0.1 60ship_x=500 70ship_y=500 80ship_orientation=0 90ship_vx=0 100ship_vy=0 110engine_force=0.3 120orb_x=500 130orb_y=30 140drag=0.9999 150orb_held=FALSE 160prev_draw_tractor_beam%=FALSE 170tractor_beam_range%=130 180tractor_beam_length%=150 190orb_vx=0 200orb_vy=0 210e=1.0:REM wall bounciness 220ship_nose_angle%=20 230ship_draw_size%=25 240REPEAT 250REM apply rotate left and rotate right (with A+S keys)... 260IF INKEY-82 ship_orientation=ship_orientation+rotation_speed% 270IF INKEY-66 ship_orientation=ship_orientation-rotation_speed% 280ship_orientation=(ship_orientation+360)MOD 360 290: 300REM: Apply tractor beam pickup logic if space bar is pressed.... 310draw_tractor_beam%=orb_held 320dist=SQR((ship_x-orb_x)^2+(ship_y-orb_y)^2) 330IF INKEY-99:IF orb_held=FALSE:IF dist<tractor_beam_range% OR prev_draw_tractor_beam%=TRUE draw_tractor_beam%=TRUE 340IF INKEY-99:IF draw_tractor_beam%:IF dist>tractor_beam_range% orb_held=TRUE 350prev_draw_tractor_beam%=draw_tractor_beam% 360ship_vy+=gravity 370S=SIN RAD ship_orientation 380C=COS RAD ship_orientation 390: 400REM handle shift key to perform Thrust... 410IF INKEY-1 ship_vx=ship_vx+S*engine_force:ship_vy=ship_vy+C*engine_force 420ship_x+=ship_vx:ship_y+=ship_vy:REM apply ship's inertia 430: 440REM apply orb physics 450IF orb_held THEN 460orb_vy+=gravity 470orb_x+=orb_vx :REM apply orb's inertia 480orb_y+=orb_vy 490REM calculate vector from ship to orb... 500ship_orb_displacement_x=(orb_x-ship_x) 510ship_orb_displacement_y=(orb_y-ship_y) 520REM rescale vector from ship to orb so that tractor beam is correct length (i.e. don't allow it to stretch) 530dist=SQR((ship_x-orb_x)^2+(ship_y-orb_y)^2) 540ship_orb_displacement_x=ship_orb_displacement_x*tractor_beam_length%/dist 550ship_orb_displacement_y=ship_orb_displacement_y*tractor_beam_length%/dist 560REM ensure orb is correct distance from the ship... 570orb_oldx=orb_x:orb_oldy=orb_y 580orb_x=ship_x+ship_orb_displacement_x 590orb_y=ship_y+ship_orb_displacement_y 600REM The above step created an impulse on the orb, which kept it at correct distance from ship. 610impulse_from_tractor_beam_x=orb_x-orb_oldx: REM this is change in momentum of orb due to tractor beam, i.e. impulse (assuming mass=1 here) 620impulse_from_tractor_beam_y=orb_y-orb_oldy 630REM This impulse must have been created by the force of the tractor beam (impulse=force*time) 640REM This tractor beam force (tension) will apply equally and opposite to the ball and the ship (Newton's 3rd law). 650REM Need to apply half of that impulse from tension force to orb (i.e. adjust its velocity accordingly...) 660orb_vx+=impulse_from_tractor_beam_x/2 670orb_vy+=impulse_from_tractor_beam_y/2 680REM apply the other half of that impulse from tension force to ship (i.e. adjust its velocity accordingly...) 690ship_vx-=impulse_from_tractor_beam_x/2 700ship_vy-=impulse_from_tractor_beam_y/2 710REM note we need the /2 above because we want to the total relative velocity change between the orb and ship to equal what was calculated as necessary to stop 720REM the tractor beam from stretching. 730ENDIF 740: 750REM apply drag... 760ship_vx=ship_vx*drag 770ship_vy=ship_vy*drag 780orb_vx=orb_vx*drag 790orb_vy=orb_vy*drag 800: 810REM implement bouncing walls.... 820IF orb_y<=0 orb_vy=ABS(orb_vy)*e 830IF ship_y<=0 ship_vy=ABS(ship_vy)*e 840IF orb_y>=1023 orb_vy=-ABS(orb_vy)*e 850IF ship_y>=1023 ship_vy=-ABS(ship_vy)*e 860IF orb_x<=0 orb_vx=ABS(orb_vx)*e 870IF ship_x<=0 ship_vx=ABS(ship_vx)*e 880IF orb_x>=1279 orb_vx=-ABS(orb_vx)*e 890IF ship_x>=1279 ship_vx=-ABS(ship_vx)*e 900: 910REM draw ship and orb: 920S1=SIN RAD(ship_orientation+ship_nose_angle%)*ship_draw_size%:C1=COS RAD(ship_orientation+ship_nose_angle%)*ship_draw_size% 930S2=SIN RAD(ship_orientation-ship_nose_angle%)*ship_draw_size%:C2=COS RAD(ship_orientation-ship_nose_angle%)*ship_draw_size% 940S=S*ship_draw_size%:C=C*ship_draw_size% 950S=S-S1:C=C-C1 960WAIT 970CLS 980GCOL 3 990LINE ship_x+S1+S,ship_y+C1+C,ship_x-S1+S,ship_y-C1+C 1000DRAW ship_x,ship_y 1010LINE ship_x+S2-S,ship_y+C2-C,ship_x-S2-S,ship_y-C2-C 1020DRAW ship_x,ship_y 1030REMFILLship_x+(S1+S)/2,ship_y+(C1+C)/2 1040GCOL 2 1050CIRCLE orb_x,orb_y,20 1060GCOL 1 1070IF draw_tractor_beam% LINE ship_x,ship_y,orb_x,orb_y 1080WAIT:WAIT 1090UNTIL 0
![Image](http://i.imgur.com/ipHpQTh.png)
I have since had a brief look through some of the disassemblies given in this thread, and I haven't studied them deeply, but I have found some comments about "angular momentum", which I don't think is the correct explanation (unless Jeremy Smith programmed this in a more complicated way than he needed to). Angular momentum is an emergent property of more basic laws of physics, i.e. newton's second law, tension, and newton's third laws, in this case. The above method in the BASIC program just considers the tractor beam as being inextensible, and calculates the necessary impulse within the tractor beam which is necessary to achieve this inextensibility, and considers the consequential momentum-changes this impulse imparts onto the orb and ship.
Statistics: Posted by mike12f — Sun Sep 08, 2024 10:30 pm