17 September 2020, 21:59 | #1 |
Registered User
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
|
Simple assembler maths problem
If you read some of my posts on here you'll know that I'm not scared to tell people how bad I am at maths, what most people find simple I find incredibly hard to work out.
Take this one for example which is pretty simple for Super Sprint. Say I have a range 0-400 for the car throttle. And I have a steer setting which goes from -300 to +300 (0 is when the car wheels are centred). When the car is idle (no throttle), the steer should quickly interpolate (I think that's the right expression) to 0, when the car is going full throttle the steer should very slowly interpolate back to 0. Been working on it a while now and I can't get it right. Any ideas anyone? |
17 September 2020, 22:11 | #2 |
Registered User
Join Date: Dec 2019
Location: Newcastle
Posts: 67
|
What do you have so far?,
If I understand you correctly, I would have a set point for the target steering position, and then move the current steering position towards the target set point by a delta amount(some fraction created by the current speed) each game frame. Then you can just fine tune the delta equation until you get something that feels right. |
17 September 2020, 22:19 | #3 |
Registered User
Join Date: May 2017
Location: AmigaLand
Posts: 459
|
Why not set car throttle in a unsigned byte (0-255) ? And same goes for steer but signed this time.
The way I understand it, if you have enough memory I'd go for a 256 bytes (may be more if more precision is needed) table of dx, where dx is the amount of steering indexed with throttle. |
17 September 2020, 22:27 | #4 | |
Registered User
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
|
Quote:
Code:
.steer_to_centre: move.l carCurrentThrottle(a4),d0 ; 400 lsr.l #8,d0 moveq #8,d1 ; 0=0, 1=1, 2=4, 3=8, 4=16 lsl.w d0,d1 tst.w carSteerMod(a4) beq .exit bmi .steer_decr_left bra .steer_decr_right ; If the car is not moving then the decrease is instant .steer_decr_left: add.w d1,carSteerMod(a4) bra .exit .steer_decr_right: sub.w d1,carSteerMod(a4) bra .exit |
|
17 September 2020, 22:54 | #5 |
Registered User
Join Date: Dec 2019
Location: Newcastle
Posts: 67
|
Using a divide would normally be needed to make this feel right else it would be too linear,
I think @LeCaravage is on the right track here, to save the need for expensive division, use a lookup table. I wouldn't even think you would require 256 lookups, if max throttle is 400, I would divide it by 16 so you can shift, and that would give you 25 lookups. Then just create the lookup table values in a spreadsheet and play around until it feels right. |
17 September 2020, 23:35 | #6 | |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,975
|
Quote:
tst.w carSteerMod(a4) beq .exit bpl.b .steer_decr_right neg.w d1 .steer_decr_right add.w d1,carSteerMod(a4) bra .exit |
|
18 September 2020, 00:59 | #7 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,039
|
This is your problem:
Code:
move.l carCurrentThrottle(a4),d0 ; 400 lsr.l #8,d0 Last edited by a/b; 18 September 2020 at 01:05. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[vbcc/win] Doing some maths.. | guy lateur | Coders. C/C++ | 21 | 21 July 2017 01:51 |
simple network problem with Flower Pot/WinUAE | mlankton | support.WinUAE | 4 | 01 March 2017 17:56 |
Seriously simple AE Problem :( | Fingerlickin_B | support.Apps | 10 | 13 March 2007 20:50 |
Simple Desert Strike Problem | itsonlyleggy | support.Games | 2 | 20 June 2006 12:24 |
help simple language problem | Aeryn26 | support.Apps | 1 | 25 May 2002 15:29 |
|
|