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 / Vehicle physics exploration

Author
Message
JonEnstrom
3
Years of Service
User Offline
Joined: 27th Apr 2020
Location:
Posted: 12th Jul 2021 00:44 Edited at: 15th Jul 2021 16:35
Inspired by some recent banter about a driving style game, I decided to take a few hours to check it out and see what's possible with AppGameKit using the bullet 3d physics commands.

Unfortunately documentation on AppGameKit 3d physics is thin to non-existent. Nonetheless so far I managed a basic vehicle driven by "impulse" motors at the wheels.

Implementing realistic steering is actually not that easy and requires the right geometry and joint connections between. In the video you can see my "tie-rod" squares (partly transparent cube inside the other transparent cube which are the wheel "hubs" technically speaking. The steering input is actuating those tie rods via linear slider joints.

So far so good. Steering still needs work, the inside tire needs to angle more than the outside tire when turning just like in real life. Next up is suspension between frame and body, and tightening up the physics so it feels good.

Then I will make a loop-de-loop model and couple other fun things to try out!





PROJECT CONCLUSIONS (STILL IN PROGRESS):

1) Use a big enough world scale for the physics engine. I recommend a tire size between 100-300 units in height for example.

2) The movement limits for "joints" are not absolute. Even if your joint isn't supposed to move in a certain direction, it actually will under enough force (read: mismatch of object size/mass) It took me a while to grasp this concept - even a "fixed" joint doesn't mean the two connected bodies will stay rigidly connected no matter what. Instead it means "fixed" within reason, until too much force happens then it will bend or break. Same applies to all kinds of joints, they only "hold" if the forces are reasonable.


Steering system details and more to come soon!
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 12th Jul 2021 10:53
Excellent work. I'll keep an eye one this!!
JonEnstrom
3
Years of Service
User Offline
Joined: 27th Apr 2020
Location:
Posted: 13th Jul 2021 00:14 Edited at: 13th Jul 2021 19:19
Ok so I tuned the steering system a little bit better by adjusting the geometry completely. Instead of a funny invisible elbow shape connection the "tie rods" are now more inline with the hubs and steering joints. This way the wheel hubs can "push" back on the steering rods. It's now working well enough that there is a certain amount of "feedback" noticeable. By feedback I mean the steering joints have a tendency to return to neutral if there is no input, just like in real life!

The next task is adding a vehicle body to the frame. So far I have tried a very simple approach of attaching a body on a two way hinge joint. So it can tilt forward and backward and side to side, by a few degrees. You can see in the first video the body moving independent of the undercarriage. Distance between body and frame is increased to see the effect more clearly. Next thing is to approximate the function of springs and struts in the four corners between body and wheel hubs, so there could be something like 4 wheel independent suspension.










Almost made it around the loop backwards but a bloody box gets in the way!



fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 13th Jul 2021 04:08
Awesome work
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 13th Jul 2021 15:19 Edited at: 13th Jul 2021 15:52
Quote: "Ok so I tuned the steering system a little bit better by adjusting the geometry completely. Instead of a funny invisible elbow shape connection the "tie rods" are now more inline with the hubs and steering joints. "


Yeah, those joints need to use Ackermann steering geometry.

There is an image on that page linked above that shows the basic principle of the tie rod joints being in line with the pivot point of the hubs and the center of the rear axle...

Of course, if the pivot point of the hubs are in the wheel instead of offset kingpins, then your geometry image would be different but still the same of the tie rods being in line with the center of the rear axle and wherever the hubs pivot point may be.



This is what is needed for tapole trike designs if you don't want to flip over or have the back wheel do bunny hops on curves.




Quote: " It's now working well enough that there is a certain amount of "feedback" noticeable. By feedback I mean the steering joints have a tendency to return to neutral if there is no input, just like in real life!"

Yes, the Ackermann geometry is self-righting. (more so the closer you are to being right on line with those tie rods)

Quote: "Awesome work"


Agreed

Reminds me of Ando's thread.

Do your frame rates see any significant drops versus doing this the other way???

That is why I wanted to keeps things simple with the flat tracks without suspension .... to avoid the presumed FPS loss involved with four wheel physics.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
JonEnstrom
3
Years of Service
User Offline
Joined: 27th Apr 2020
Location:
Posted: 13th Jul 2021 17:31 Edited at: 13th Jul 2021 17:40
Quote: "Do your frame rates see any significant drops versus doing this the other way???"


No slowdown at all, at least on my hardware the physics engine runs comfortably even up to 600hz (but I am actually using 60hz and 60 fps also). Keep in mind the 3d physics engine updates separately from Sync(), so that means you don't have to run both at the same rate. For dice rolling, for example, the documentation suggests running the physics engine at least 300hz, but of course that doesn't mean you need to render 300fps. You just would call the physics update 5 times per Sync() call assuming 60 fps. For dice that's fine, but in general you don't want to call the physics step more often than needed, because it will actually stop working.

From what I can see the physics calculations will actually never slow down the main thread. How is that possible? If you call the physics world update too many times in a frame, or have too many physics objects being calculated for the frame and the engine "runs out of time" to complete the work, the unfinished work is simply abandoned so the next frame can get rendered without delay. It's not a bad design choice, the physics calculations are often just slightly moving a bunch of 3d objects each frame, so if a frame or two get dropped when CPU cycles get tight for whatever reason, it's not a problem really. However for this reason it makes sense to call physics engine as few times as possible that will still achieve smooth action.

I am going to eventually edit my first post in this thread, and offer my conclusions regarding this project so it could maybe help out others interested a similar project. I may also fill in a bunch of the missing/thin AppGameKit documentation in the 3d physics category, along with basic code examples using the commands in context.
JonEnstrom
3
Years of Service
User Offline
Joined: 27th Apr 2020
Location:
Posted: 14th Jul 2021 16:56 Edited at: 14th Jul 2021 18:30
Ok so I have set up a suspension system for the rear wheels so far, however I immediately noticed an issue. The suspension uses a basic slider joint to connect hubs with the body, and uses a motor to apply a constant pressure. If the pressure amount is too high then the wheels act rigid and the suspension won't compress easily. If the pressure amount is too low then it compressed easily over bumps but hardly rebounded very quickly, kind of squishy feeling. So it turns out in real life shocks have a "progressive" rate throughout the travel, not a single rate and I needed to do something similar here.




This video shows the realistic suspension dive when accelerating or braking from backwards motion.

JonEnstrom
3
Years of Service
User Offline
Joined: 27th Apr 2020
Location:
Posted: 14th Jul 2021 17:00 Edited at: 15th Jul 2021 16:24
I grabbed a free dump truck model and noticed there's a perfect spot to separate the dumper and use a physics hinge joint. Then I added a slider joint to act as the hydraulic ram.







Funny stuff when I made the boxes weigh a lot! I wondered why the steering wasn't working... oh the front wheels are off the ground!

JonEnstrom
3
Years of Service
User Offline
Joined: 27th Apr 2020
Location:
Posted: 17th Jul 2021 01:05
Check this out, I decided to rig up this model of a Caterpillar 789c (this is a free royalty free model from cgtrader.com).


More work to be done, I am going to try to make the dump rams from the model actuate, also going to rig the steering wheel, gear shift and window wiper for ultimate immersion in the cockpit view!


Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 17th Jul 2021 02:33
that's hilarious. and, nice work. keep it coming
[My Itch.io Home] [Community Apps on Itch.io]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 17th Jul 2021 06:43
Excellent work!!
Caterpillar doing a wheely. I don't think i'v seen that before.
Maybe turn on shadows. It looks like it's floating a bit
JonEnstrom
3
Years of Service
User Offline
Joined: 27th Apr 2020
Location:
Posted: 18th Jul 2021 20:55 Edited at: 18th Jul 2021 21:13
Ah thanks great idea about the shadows! I hadn't given one minute though about lighting until you mentioned it actually.

I've completed a few more items including fully rigging the dump rams, steering wheel, and started on the window wiper. I have also started experimenting with conveyor belts, just need to work on angled belts that can raise or lower material instead of just translate it sideways.

Keep in mind the original model has no animation or separated parts to start with. I used blender to chop up the model into the wheels, the main vehicle, the dump bed, the hydraulic ram "bodies" attached to the left and right of the vehicle, and the "eyelets" that attach to the dumper.

The dump bed has 9 boxes that make up the collision shape. I have very tightly tuned the shapes and positions for very realistic collisions with all parts of the dump bed.

The model has no actual "ram" part however (the metal rod that extends) so I had to manually rig "fake" ones by simply placing a non-physics object in the right spot and adjusting to the right length and angle.

The steering wheel is also manually rigged (the rotation of the object is based on the difference in angle between the wheel and the vehicle body), so the wheel turns based on the real wheel position, at realistic ratio.

The window wiper still needs work! It's a double hinged setup in real life that may be more work than it's worth to replicate with physics. So far I am manually sweeping it back and forth. Gear shift is still fixed in place but I will make it swing back and forth for forward and reverse.

Collision shapes for rocks changed to convex hulls - much tighter stacking and more realistic collisions now, although you can see at the end of the video I need to tweak their friction down a little!

Many camera modes added including "dump-cam" mounted on the dumper! Num pad 0-9 changes cameras.

Dump rams:



Dump bed collision:



Camera modes & Conveyors
JonEnstrom
3
Years of Service
User Offline
Joined: 27th Apr 2020
Location:
Posted: 19th Jul 2021 00:58
More conveyor belt stuff.

JonEnstrom
3
Years of Service
User Offline
Joined: 27th Apr 2020
Location:
Posted: 22nd Jul 2021 18:43 Edited at: 22nd Jul 2021 18:56
Added rear view mirrors on the drivers and passenger side of the Cat.



blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 22nd Jul 2021 22:05
Looks very cool. Does it need to be flipped right to left?
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 22nd Jul 2021 23:11 Edited at: 22nd Jul 2021 23:14
Quote: "Added rear view mirrors"

your world has levitating conveyor belts but no backup cameras?

if we're going for this much detail, dont forget to add the "objects may appear larger" disclaimer on the mirror
[My Itch.io Home] [Community Apps on Itch.io]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]
JonEnstrom
3
Years of Service
User Offline
Joined: 27th Apr 2020
Location:
Posted: 23rd Jul 2021 20:42 Edited at: 24th Jul 2021 00:49
Quote: "Looks very cool. Does it need to be flipped right to left?"


Oh yea ... derp! You would think I would notice that hahaha! Fixed.

Quote: "your world has levitating conveyor belts but no backup cameras?"


Great idea, that makes sense and wasn't too tough to add either! And it's "objects may BE larger (closer) than they appear!" Just for clarity! I'll see about adding it too lol.

In the meantime I also improved the camera FOV in the cab and threw in power windows!

Jack
19
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 23rd Jul 2021 21:48

Login to post a reply

Server time is: 2024-03-29 06:30:28
Your offset time is: 2024-03-29 06:30:28