Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / 3D Car Physics

Author
Message
sprotz
6
Years of Service
User Offline
Joined: 26th Oct 2017
Location:
Posted: 29th Sep 2020 10:30
Is there a code / example to implement any sort of car physics on AgK ? I've searched far and wide all web and they say that car physics is not supported but I've seen that Appgamekit uses Bullet Physics and Bullet has a simple raycast vehicle controller. I saw a raycast car example video for Appgamekit but no code, example project source or anything, so there has got to be some way of implementing some sort of car physics that is semi realistic with at least drifting and spinout. I would like to know how to implement that.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
sprotz
6
Years of Service
User Offline
Joined: 26th Oct 2017
Location:
Posted: 30th Sep 2020 06:47
I know about that example, but how could I improve it to add drifting and spinout ? ( spinout is when the rear wheels lose traction when cornering and the car spins out of control )
I know that in top down 2d physics, that is achieved by adding hinge joints as wheels to the rigidbody, and adjusting friction accordingly to each of the four wheels. Could this be translated into 3D as well ? Using wheel colliders instead of rays ?
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 30th Sep 2020 12:16
If you know how to do it in 2D then you know how to do it in 3D too. Do it exactly the same way but ignore the Z component.
You could take it a step further and check first to see if the wheel is in contact with the ground. Zeroing out any traction values if it isn't.
sprotz
6
Years of Service
User Offline
Joined: 26th Oct 2017
Location:
Posted: 30th Sep 2020 13:29
Ok, I will try experiment with the existing physics functions and I will post an example here if successful.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 30th Sep 2020 21:59 Edited at: 30th Sep 2020 22:02
Here is a topdown example using box2d physics
Kartgame.rar is a demo where i've mapped the 3D co-ordinates to 2D (The 3D x,z values are mapped to Box2D x,y). The only drawback here is the track has to be flat (The steering is terrible, sorry 'bout that)
hotdog.rar is a game i recently made for the lowrez jam (I turned off the lowrez bit). It uses the simple kart physics but it also implements drift.

At line 216 and 224 of MoveVehicle.agc it calculates drift by taking the vector the car is traveling at and the vector of the force being applied to the car and lerps a value between those two.
You could easily check if the difference between those two values was too big and make the vehicle spin out (See gameplay.agc line 424)

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-04-18 08:48:33
Your offset time is: 2024-04-18 08:48:33