+johnnywc Posted September 9, 2006 Share Posted September 9, 2006 (edited) Hello all, I know both of these topics have been discussed at length before, yet I still can't seem to grasp an easy way to apply friction to a moving object. I'm trying to simulate the tank movement in Rip Off. I have 16 directions, each with a predefined horizontal and vertical component. For the tank, I have the following variables: TankXf ; fractional part of tank X coord TankX ; integral part of tank X coord TankYf TankY TankHf ; fractional part of horizontal speed TankH ; integral part of horizontal speed TankVf ; fract. part, vertical speed TankV ; int. part, vert speed The speeds are defined in a table. So, assuming X holds the current direction (0-15), motionHf, motionH holds the 16 possible horizontal speeds and motionVf, motionV holds the 16 possible vertical speeds: lda TankHf clc adc motionHf,x sta TankHf lda TankH adc motionH sta TankH lda TankVf clc adc motionVf,x sta TankVf lda TankV adc motionV sta TankV NOTE: motionH and motionV are 0 for positive directions and -1 for negative directions. motionHf and Vf are either +/- a value based on whether the direciton is negative or positive. I then add TankHf, TankH to TankXf, TankX and add TankVf, TankV to TankYf, TankY. This produces good Asteroids type subpixel movement (albeit with no maximum speeds). So, I'm looking for a way to: 1) add friction (have the values go to 0 when thrust is not applied) 2) have a maximum H and V speed (this may be solved with (1) Of course, I'm looking to have this simulate the movement in Rip Off as close as possible. Any ideas? Thanks! Edited September 9, 2006 by johnnywc Quote Link to comment Share on other sites More sharing options...
djmips Posted September 9, 2006 Share Posted September 9, 2006 TJ reccomends dividing your speed by some power of two and subtracting that from your current speed. I can't think of a more elegant solution. Quote Link to comment Share on other sites More sharing options...
+johnnywc Posted September 9, 2006 Author Share Posted September 9, 2006 TJ reccomends dividing your speed by some power of two and subtracting that from your current speed. I can't think of a more elegant solution. Thanks - I did read that thread but I can't seem to find an elegant way to implement it. Any examples using the data structures I have above? Is it as simple as getting TankHf, TankH, doing an lsr a couple times (how many)? and then subtracting that from the original TankHf/TankH? (and the same for the TankV/Vf?) I tried something similar and the acceleration was very slow; also, it didn't work in the reverse direction. Any help is appreciated! Thanks again, Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted September 9, 2006 Share Posted September 9, 2006 (edited) I wonder why it didn't work for you. Probably you didn't shift often enough. And you have to make sure, that you shift arithmetically (shifting 1s into bit 7) when the speed is negative. For will limit the maximum speed, but won't reduce the speed down to exactly zero. Just subtracting 1 more, should solve that problem. Check my Cave1K code (ySpeed). Edited September 9, 2006 by Thomas Jentzsch Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted September 9, 2006 Share Posted September 9, 2006 (edited) Here is some stripped code and binary, showing friction only. Notice the difference acceleration and friction values for x and y. The combination of acceleration and friction values gives the maximum speed. EDIT: Fixed version. Friction02.bin Friction02.zip Edited September 9, 2006 by Thomas Jentzsch Quote Link to comment Share on other sites More sharing options...
gambler172 Posted September 20, 2006 Share Posted September 20, 2006 Here is some stripped code and binary, showing friction only. Notice the difference acceleration and friction values for x and y. The combination of acceleration and friction values gives the maximum speed. EDIT: Fixed version. Hallo Thomas Wäre toll,wenn du mal was wirklich Gutes mit Batari Basic machen könntest.Dieser Sprite sieht doch schon recht gut aus(besser als andere).Wäre schön mal was vom Profi zu sehen.Ich bin überzeugt,dass du einiges aus Batari Basic rausholen könntest. Gruss Walter Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted September 20, 2006 Share Posted September 20, 2006 Wäre toll,wenn du mal was wirklich Gutes mit Batari Basic machen könntest.Dieser Sprite sieht doch schon recht gut aus(besser als andere).Wäre schön mal was vom Profi zu sehen.Ich bin überzeugt,dass du einiges aus Batari Basic rausholen könntest. Warum sollte ich? 1. Ist BASIC keine Herausforderung 2. Kann ich mit Assembler alles machen was geht und nicht nur was BASIC kann 3. Der Sprite ist wirklich nicht besonderes Nee, BASIC ist nichts für mich. Quote Link to comment Share on other sites More sharing options...
gambler172 Posted September 20, 2006 Share Posted September 20, 2006 Wäre toll,wenn du mal was wirklich Gutes mit Batari Basic machen könntest.Dieser Sprite sieht doch schon recht gut aus(besser als andere).Wäre schön mal was vom Profi zu sehen.Ich bin überzeugt,dass du einiges aus Batari Basic rausholen könntest. Warum sollte ich? 1. Ist BASIC keine Herausforderung 2. Kann ich mit Assembler alles machen was geht und nicht nur was BASIC kann 3. Der Sprite ist wirklich nicht besonderes Nee, BASIC ist nichts für mich. Hallo Thomas Logisch,dass Basic für dich keine Herausforderung ist.Ich jedoch wäre froh,wenn ich es könnte.Ich warte immer noch auf den Kurs von Michael. Klar kannst du in Assembler alles machen.aber du(als Top-Programmierer)könntest wahrscheinlich mehr herausholen,als viele Andere. Ja,für Assembler Verhältnisse ist der Sprite nix Besonderes,aber wenn man mal sie anderen Sprites so sieht,dann ist dein Smilie richtig gut. Gruss Walter Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted September 20, 2006 Share Posted September 20, 2006 Klar kannst du in Assembler alles machen.aber du(als Top-Programmierer)könntest wahrscheinlich mehr herausholen,als viele Andere. Kaum, BASIC ist das Limit, nicht meine Fähigkeiten. Ja,für Assembler Verhältnisse ist der Sprite nix Besonderes,aber wenn man mal sie anderen Sprites so sieht,dann ist dein Smilie richtig gut. Das hat nun wirklich überhaupt nichts mit Basic zu tun. So'n Sprite kannst du in BASIC problemlos auch erstellen. Es ist ja nichtmal mehrfarbig. Ich bin was Grafik angeht nun wirklich kein Experte. Wenn andere BASIC Sprites deiner Meinung nach noch schlechter aussehen als meine, dann hat das andere Gründe. Quote Link to comment Share on other sites More sharing options...
Tom Posted September 27, 2006 Share Posted September 27, 2006 I Just spent a fair amount of time playing around with Thomas' sample Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted September 27, 2006 Share Posted September 27, 2006 I Just spent a fair amount of time playing around with Thomas' sample If you like it, maybe you want to look into my blog. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.