Page 1 of 2

Car physics

Posted: Sat Jan 20, 2007 1:06 pm
by BalrogSoft
Hi, i will make a car game for mobile phones on next months, after make some research i ported a simple source code to PB, i didn't interested really to study car physics. I made some weeks ago a port of a car physics example from a java source, it isn't perfect, it have a bug when you break the car, but it could be useful to the community:

Car Physics example: http://www.balrogsoftware.com/download/carphysics.zip

Posted: Sun Feb 04, 2007 3:22 am
by u9
I've been looking for some car physics too. Could you post where you found the original? Maybe there was some documentation or other info along with it?

Posted: Fri Feb 09, 2007 1:05 pm
by BalrogSoft
I don't have the url where i found the code, i have it on a old harddisk, i changed the harddisk of my notebook some weeks ago. I will try to find it this weekend.

Posted: Tue Mar 27, 2007 9:30 pm
by thyphoon
Great ! But i think you use the Marco Monster tutorial to do it, isn'it ?
the url is :http://home.planet.nl/~monstrous/tutcar.html
But to day it's offline. I search this tutorial since many day. ! If you found this document on your hardisk Pleeeeeeeeeease post it :P i think you will do lot of happy people !

best regards and excuse me for my bad english !

Thy

Posted: Wed Mar 28, 2007 4:21 am
by thyphoon
Thanks to svgaman from the french forum !
if you want this tutorial
http://web.archive.org/web/200602200627 ... utcar.html :P

Posted: Thu Oct 11, 2007 8:47 am
by BalrogSoft
Hi, i know that i didn't post here since months, sorry for this offline stage, i'm working on a new company and i didn't have enough time for personal projects in PB, but i still use PB to test algorithms and small tools for web or game development. Here you will find a new version of simple car physics that works fine, i got the code from a Flash racing game, and i ported it to PB, this code is the previous stage for my racing game for mobile phones. You can use the graphic of the first example.

NOTE: I have edited the code, it had a bug when you try to go backwards.

Code: Select all

InitSprite()
InitSprite3D()
InitKeyboard()

Procedure.f min(a.f, d.f)
  If a < d
    ProcedureReturn a
  Else
    ProcedureReturn d
  EndIf
EndProcedure

Procedure.f max(a.f, d.f)
  If a > d
    ProcedureReturn a
  Else
    ProcedureReturn d
  EndIf
EndProcedure

Procedure.f sign(a.f)
  If a.f < 0
    ProcedureReturn -1.0
  Else
    ProcedureReturn 1.0
  EndIf
EndProcedure


Procedure.f adjust(v.f,threshold.f,maximum.f)
		vx.f = 0
		If (v <= threshold) 
		  vx=(v/threshold)*1.0
		Else 
		  vx = 1
		EndIf
		ProcedureReturn vx
EndProcedure
	
Quit.b = #False

accel.f = 0.2 ; acceleration due To gas (up arrow)
steer.f = 0.08 ; steering tightness
steer_normal.f = 0.08 ; Default Steering
steer_handbrake.f = 0.099 ; Incremental increases For handbrakeys
steer_threshold.f = 4 ; Speed where steering at its most manouvreable
MINspd.f = -5 ; max reverse speed
MAXspd.f = 22	; max speed on straightaway
MAXskiddisplay.f = 2 ; Display skids on slides till this value reached
MAXturnSpd.f = 10 ; maximum speed While turning
MaxTurnSkid.f = 18 ; Maximum speed in turn before skidding
deccel.f = 0.92 ; decelleration due To brakes (down arrow)
handbrake.f = 0.93 ; decelleration due To brakes (down arrow)
handbrake_traction.f = 20 ; Amount of slide For handbrake higher is more
drift.f = 0.98 ; deceleration after letting off gas

speed.f = 0  ; duuuh!
surface.f = 3 ; Tar = 10 gravel = 1 ice = 0.5 
traction.f = 5 ; the higher the more slippery init value
traction_max.f = 1 ; Max Traction
Dim vector.f(1) ; vector of the direction of the car
bounceBack.f = 0.6 ; percent of speed when bounced back from hitting an obstacle

angle.f

collide = false ; Used To make sure car doesnt get stuck in collision checks
	
	
If OpenWindow(0, 0, 0, 640, 480, "Car Physics", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  OpenWindowedScreen(WindowID(0), 0, 0, 640, 480, 0, 0, 0)
  
  LoadSprite(0, "car.bmp", #PB_Sprite_Texture)
  CreateSprite3D(0, 0)
  
  Repeat
    
    WEvent = WindowEvent()
    
    If WEvent = #PB_Event_CloseWindow
      Quit = #True    
    EndIf
    
    rotation = angle * 180 / #PI
    
    ExamineKeyboard()
    UP = KeyboardPushed(#PB_Key_Up) >> 7
    DOWN = KeyboardPushed(#PB_Key_Down) >> 7    
    HAND = KeyboardPushed(#PB_Key_LeftControl) >> 7
    LEFT = KeyboardPushed(#PB_Key_Left) >> 7
    RIGHT = KeyboardPushed(#PB_Key_Right) >> 7
    
    UD = UP - DOWN
    LR =  RIGHT - LEFT
    
    If LR
      angle + (LR*steer*adjust(Abs(speed),steer_threshold, MAXSpd))
    EndIf
    
    
    If UD = #False
        speed * drift
    ElseIf UD <> #False And HAND = #False
        speed = Min(Max(speed+UD*accel,MINspd),MAXspd)
    EndIf
    
    If (Abs(speed) < accel/2) 
      speed = 0
    EndIf
  
    If HAND
       speed  * handbrake
	If (speed > MAXskiddisplay)
	    steer = steer_handbrake
	EndIf
	traction = handbrake_traction/surface
    Else 
	traction = Max(traction_max, Abs((speed-MAXturnSpd)/surface))
        steer = steer_normal
    EndIf

    If (speed < 0 ) 
      traction = 1.0
    EndIf
    
    xv.f = ((Cos(angle) * speed) - vector(0))/traction
    yv.f = ((Sin(angle) * speed) - vector(1))/traction
     
    vector(0) + xv.f
    vector(1) + yv.f
    
    track_x.f + vector(0)
    track_y.f + vector(1)


    StartDrawing(ScreenOutput())
    DrawText(0, 0, "Car x: " + StrF(x))
    DrawText(0, 20, "Car y: " + StrF(y))
    DrawText(0, 60, "speed: "+ StrF(speed))
    DrawText(0, 80, "angle: " + StrF(rotation))
    StopDrawing()
    
    Start3D()
    RotateSprite3D(0, rotation + 275, 0)
    DisplaySprite3D(0, track_x, track_y, 255)
    Stop3D()
    
    FlipBuffers()
    ClearScreen(0)
    Delay(30)
    
  Until Quit = #True
  
  CloseWindow(0)
EndIf

Posted: Sun Dec 09, 2007 2:56 am
by BriceManuel
.

Posted: Sun Dec 09, 2007 3:35 am
by LuCiFeR[SD]
Edited Per request

Posted: Sun Dec 09, 2007 6:16 am
by Heathen
Removed original reply at mod's request (troll has been banned now)

Great job Balrog!!!! All of us here appreciate everything you have shared with the community. I have personally learned from you :)

Posted: Sun Dec 09, 2007 10:19 am
by blueznl
Troll alert (ie not Balrog but PurePWNRER!!)

I'm not the first to point fingers, although I know Berikco is lazy (he said so himself), Fred's in love with TheHoff (no other reason why he would let Hasslehof's image all over the board) and the rest of us is nuts (including me, although perhaps excluding TheFool and PsychoPantha as they both may qualify as either insane or utterly mad due to heavy machine code indulgence). However, in your case, mister PurePWNRER, I fear you are nothing but a troll.

I've done a quick search on your name for your posts, and if negativity is a virtue, you're lined up for the top spot in the next Nobel price.

(And yes, I can be negative as well, but at least I TRY not to let that get the better part of me.)

So, why not leave out the criticism and show this board your good side? You're scaring away the girls...

Posted: Sun Dec 09, 2007 7:05 pm
by Berikco
PurePWNRER wrote:
NOTE: I have edited the code, it had a bug when you try to go backwards.
It still does, dummy ;)

Following your abomination of "car physics" ( ie it's just a kid's hack, I don't see why would anyone call this physics in the first place )
I only see one dummy here, who goes very far over the line.
You also like to use multiple nicks in this forum, witch is not appreciated.
Please stay away if this is all you can post!

Balrog coded incredible things, helped numerous of people here, only problem is he visits us not enough these days :(

Posted: Sun Dec 09, 2007 7:34 pm
by Berikco
blueznl wrote:...although I know Berikco is lazy...
Just don't tell this to everybody will you! :wink:


So, removed the trol, everybody edit there message, so we can continue this useful thread.

Posted: Mon Dec 10, 2007 9:55 am
by BriceManuel
edited message per your request.

Re: Car physics

Posted: Sun Apr 24, 2016 1:47 am
by Psychophanta
BalrogSoft wrote:Hi, i will make a car game for mobile phones on next months, after make some research i ported a simple source code to PB, i didn't interested really to study car physics. I made some weeks ago a port of a car physics example from a java source, it isn't perfect, it have a bug when you break the car, but it could be useful to the community:

Car Physics example: http://www.balrogsoftware.com/download/carphysics.zip
No available file :?

Re: Car physics

Posted: Sun Apr 24, 2016 2:57 am
by Demivec
Psychophanta wrote:
BalrogSoft wrote:Hi, i will make a car game for mobile phones on next months, after make some research i ported a simple source code to PB, i didn't interested really to study car physics. I made some weeks ago a port of a car physics example from a java source, it isn't perfect, it have a bug when you break the car, but it could be useful to the community:

Car Physics example: http://www.balrogsoftware.com/download/carphysics.zip
No available file :?
It is available in the 'Internet Archive Wayback Machine'. :wink: