Author Topic: The need for speed!  (Read 7452 times)

0 Members and 1 Guest are viewing this topic.

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
The need for speed!
« on: May 09, 2012 »
I will try and explain the problem to you

Car racing game, and i have the Rpm that when you press the up key goes from 0 to 55.
Then at the same time i need the Mph to go from 0 to 30.
It's when slowing down the car there is a problem as the Mph goes in to negative numbers before the Rpm reaches 0
I have tryed all sorts but i just can't sort it out.
Thanks for any help guys.

Code: [Select]
#Minimum_Rpm = 20
Global Gear = 1

Enumeration
  #Accelerate
  #Brake
  #SlowDown
EndEnumeration

Structure GearAccel
  GearUpAt.f                                                 ; RPM for next gear (up)
  GearDownAt.f                                               ; RPM for next gear (down)
  AccelUp.f                                                  ; RPM to add when accelerating
  AccelBreak.f                                               ; RPM to subtract when braking
  AccelDown.f                                                ; RPM to subtract when automatic slow down
  AccelDiff.f                                                ; RPM difference between gears
  SpeedUp.f                                                  ;
  SlowDown.f                                                ;
EndStructure

Global Dim GearTable.GearAccel(5)

; Init GearTable
GearTable(1)\AccelUp    = 0.5 : GearTable(1)\GearUpAt   = 50 ; change up at
GearTable(1)\AccelDown  = 0.5 : GearTable(1)\GearDownAt = 5  ; change down at
GearTable(1)\AccelBreak = 0.5 : GearTable(1)\AccelDiff  = 20 ; rpm between change
GearTable(1)\SpeedUp    = 0.1 : GearTable(1)\SlowDown  = 0.1

GearTable(2)\AccelUp    = 0.4 : GearTable(2)\GearUpAt   = 55
GearTable(2)\AccelDown  = 0.4 : GearTable(2)\GearDownAt = 15
GearTable(2)\AccelBreak = 0.4 : GearTable(2)\AccelDiff  = 20
GearTable(2)\SpeedUp    = 0.1 : GearTable(2)\SlowDown  = 0.1

GearTable(3)\AccelUp    = 0.3 : GearTable(3)\GearUpAt   = 60
GearTable(3)\AccelDown  = 0.3 : GearTable(3)\GearDownAt = 25
GearTable(3)\AccelBreak = 0.3 : GearTable(3)\AccelDiff  = 20
GearTable(3)\SpeedUp    = 0.1 : GearTable(3)\SlowDown  = 0.1

GearTable(4)\AccelUp    = 0.2 : GearTable(4)\GearUpAt   = 65
GearTable(4)\AccelDown  = 0.2 : GearTable(4)\GearDownAt = 35
GearTable(4)\AccelBreak = 0.2 : GearTable(4)\AccelDiff  = 20
GearTable(4)\SpeedUp    = 0.1 : GearTable(4)\SlowDown  = 0.1

GearTable(5)\AccelUp    = 0.1 : GearTable(5)\GearUpAt   = 70
GearTable(5)\AccelDown  = 0.1 : GearTable(5)\GearDownAt = 45
GearTable(5)\AccelBreak = 0.1 : GearTable(5)\AccelDiff  = 20
GearTable(5)\SpeedUp    = 0.1 : GearTable(5)\SlowDown  = 0.1

Procedure Transmission(accel)
 
  Shared Motor
 
  If accel = #Accelerate
    If Rpm >= GearTable(Gear)\GearUpAt And Gear < 5          ; Accelerate - Gear Up
      Rpm - GearTable(Gear)\AccelDiff
      Gear + 1
    Else
     
      Rpm + GearTable(Gear)\AccelUp                          ; Accelerate
      Mph + GearTable(Gear)\SpeedUp                         ; Speed up
       
      If Gear = 5 And Rpm > 50 : Rpm = 50 : EndIf
      If Gear = 5 And Mph > 30 : Mph = 30 : EndIf
     
    EndIf
  ElseIf accel = #Brake
   
    Rpm - GearTable(Gear)\AccelBreak                         ; Brake
    Mph - GearTable(Gear)\SlowDown                          ; Slow down
   
    If Rpm <= GearTable(Gear)\GearDownAt And Gear > 1        ; Brake - Gear Down
      Rpm + GearTable(Gear)\AccelDiff
      Gear - 1
    ElseIf Gear = 1
      If Rpm < #Minimum_Rpm : Rpm = #Minimum_Rpm : EndIf
      If Mph < #Minimum_Mph : Mph = #Minimum_Mph : EndIf
    EndIf
  Else
   
    Rpm - GearTable(Gear)\AccelDown                          ; Slow Down
    Mph - GearTable(Gear)\SlowDown
   
    If Rpm <= GearTable(Gear)\GearDownAt And Gear > 1        ; Slow Down - Gear Down
      Rpm + GearTable(Gear)\AccelDiff
      Gear - 1
    ElseIf Gear = 1                                          ; Slow Down - 1st Gear minimum Rpm
      If Rpm < #Minimum_Rpm : Rpm = #Minimum_Rpm : EndIf
      If Mph < #Minimum_Mph : Mph = #Minimum_Mph : EndIf
    EndIf
  EndIf
 
  ; Change the engine freq acording to Rpm
  SoundFrequency(Motor,Rpm*400)
  ; Return Mph
  ProcedureReturn Mph
 
EndProcedure

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: The need for speed!
« Reply #1 on: May 09, 2012 »
Can you post the project please Pot Noodle.

If you have a DropBox or Google Drive account, they're very handy for posting projects and stuff. Both are free for 5GB storage.
raizor

Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: The need for speed!
« Reply #2 on: May 09, 2012 »
i have the Rpm that when you press the up key goes from 0 to 55.
Then at the same time i need the Mph to go from 0 to 30.
How about
mph= rpm * 30 / 55;
?

Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: The need for speed!
« Reply #3 on: May 09, 2012 »
Thanks hellfire, the problem with that is i don't wont the MPH to drop & rise with gear change etc..
Raizor here is the link

http://dl.dropbox.com/u/71849177/Jaguar%20XJ220.rar

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: The need for speed!
« Reply #4 on: May 09, 2012 »
Thanks Pot Noddle. I'll take a look.
raizor

Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: The need for speed!
« Reply #5 on: May 10, 2012 »
Cheers Raizor, looking forward to see what you come up with  ;D

Offline Canopy

  • Atari ST
  • ***
  • Posts: 208
  • Karma: 20
    • View Profile
Re: The need for speed!
« Reply #6 on: May 12, 2012 »
isn't the answer something like

mph= (rpm * gearing_modifier) *30 / 55;

thats how it is in a real car.. you'll have to play with values in gearing_modifier to stop it going wild

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: The need for speed!
« Reply #7 on: May 20, 2012 »
Pot Noodle,

I've had a look at this and noticed a few things. When the gear shifts up, the speed actually decreases as the gear shifts, which is a bit odd. The way you're handling the whole transmission system seems a little over complex to me. I'd probably rewrite it and try to make it simpler if I were you. You should be able to totally do away the GearTable table and the GearAccel stuff. I've had a play around with it in its current state, but any changes I make have a lot of knock-on effect throughout the program (track flying at crazy speed or running really slowly).

I'd probably have a global acceleration variable that acts as an RPM modifier. As the UP key is held down, the acceleration factor gradually increases up to a set threshold, and gradually decreases when the UP key is released. When the DOWN key is held (decelerate), the acceleration factor would decrease at a greater rate. You might want to have both an acceleration factor and deceleration factor variable and use these together to determine the rate at which the RPM is modified, but this might not be necessary, I'd try without it first.

As far as gear changes, I'd check the current RPM and if it's above a certain level, change the gear up, below a certain level, change the gear down. The RPM rate that causes a gear change would be different depending on current gear, so you'll need to take the current gear into account when determining this threshold. You should be able to come up with a formula to control this without relying on lookup tables.

I'd concentrate on getting the numbers working properly and ignore the effect on the track speed at first. Once the RPM, Gears and MPH are playing nicely together, you can adjust the track movement to suit.

I hope this helps a little bit, sorry I don't have a magic fix :(

p.s. It's coming along nicely though and looks great so far.



raizor

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: The need for speed!
« Reply #8 on: May 21, 2012 »
The problem is that in a real car rpm and speed are not related.  I can be doing 100mph or 10mph at 3000rpm depending what gear I'm in, and I can even be doing 100mph with almost 0rpm if I was doing 120mph and took my foot off the gas and completely.  Or put my foot on the clutch and jam the gas down, I can be doing 6000rpm and 0mph ;)

Jim
Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: The need for speed!
« Reply #9 on: May 21, 2012 »
Thanks for your time Raizor  :'( I have to be truthfull and say I was hopping for an answer or even a rewrite!..
O'well looks like another one for the trash can as I just can't move forward with this project.
Thanks Jim for your input.

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: The need for speed!
« Reply #10 on: May 22, 2012 »
Thanks for your time Raizor  :'( I have to be truthfull and say I was hopping for an answer or even a rewrite!..
O'well looks like another one for the trash can as I just can't move forward with this project.
Thanks Jim for your input.

It's quite a specific project, so getting my head around it and rewriting it would likely take me quite a while. Besides, if I did rewrite the whole lot for you it would defeat the object a little as you wouldn't really learn much from that. Don't be so quick to admin defeat, I'm sure you can get it working if you stick with it :)
raizor

Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: The need for speed!
« Reply #11 on: May 22, 2012 »
OK Raizor i think i have it in the bag  :D I stopped up last night and started from scratch, putting what i have learned in to Perspective and few tweaks her and there and it's now looking like the real thing.  :updance:
I will let you know what i did to sort it out once i have finished it.
Thanks.

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: The need for speed!
« Reply #12 on: May 22, 2012 »
OK Raizor i think i have it in the bag  :D I stopped up last night and started from scratch, putting what i have learned in to Perspective and few tweaks her and there and it's now looking like the real thing.  :updance:
I will let you know what i did to sort it out once i have finished it.
Thanks.

Great news! :D
raizor

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: The need for speed!
« Reply #13 on: May 22, 2012 »
Glad you haven't trashed this as it has so much potential.

Keep on going with it :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 1217
  • Karma: 230
    • View Profile
    • Homepage
Re: The need for speed!
« Reply #14 on: May 22, 2012 »
Ditto, what I saw looked really cool!  :)
www.kirl.nl
Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: The need for speed!
« Reply #15 on: May 22, 2012 »
Thanks for the advice guys i will Carry on.