[ASSETS] [OPEN SOURCE] Tanks, tracks and N-wheeled vehicles

Thank you! I was reading Minaosis’ post regarding his project and he had similar issues with physics constraints. I’ve applied some of the tips mentioned by TooManyFps and it seams to work better but I didn’t tested all the parts yet.

nice constraints example!

Here’s my latest addition to the test.
No tweaks yet to suspension, weight etc. And I have no idea about engine torque and gear ratio’s for a tiger tank (yet)

I think there should also be collision for the sprocket and idler.
It depends on tank design, but with some tanks that front sprocket will hit an obstacle very quickly and not having it contribute when going over something steep or high is weird.
Maybe an idea to turn that also into a “roadwheel” without suspension so that you can have a SprocketCollision Radius and IdlerCollision Radius. Manually adding collision to it does not seem to work very well.

I will also play around with with suspension length, I can imagine it not being a lot for the tiger… and that will help probably help the sprocket not going so low on the front.

I will update my blueprint now to the latest version so I can check you latest changes to the automatic gearbox.

Here’s a clear example where you can see that front sprocket also contributing (or at least colliding)

[I’ll comment on this first] I’ve seen Anders’ work before and from what I understood he either coded a custom physics for rope like threads or some clever use of cloth simulation, both cases is most likely custom Verlet particles simulation. Unless it’s PhysX cloth but I don’t think it has such a degree of interaction with other rigid bodies out of the box. In all of his demos with tracked vehicles, velocities are rather low, which might be hiding a fact that simulation at high velocity is as unstable as building threads out of constrained rigid bodies. I can be wrong here, at some point tank does go at about 50km/h, which is rather high. It would be interesting to know how he build it but I haven’t seen him sharing implementation details on Unity forums. This is the most realistic simulation of threads I’ve seen so far.
There is also this package: Unity Asset Store - The Best Assets for Game Making
Judging from videos and documentation, tracks are simulated as well.

I want to investigate this route but my concern is on performance side. Resolving such simulation for a 50 particles per tank is most likely expensive, perhaps some smart tricks can be made to improve that. But you need to take into account that non of the AAA games do that and even IL-2 went with a simpler approach. Don’t know the true reason behind this, I’m not an expert.

There is an alternative approach which I was thinking about for quite some time. The main issue I want to solve, is not a realistic track simulation per se but giving the same maneuverability to the tank as it would have in real-life. Which leads to discussion regarding your previous post on sprocket collision.

I need to find a solution for calculating friction at arbitrary point. Right now I can calculate it only underneath the wheels. The reason for that is to calculate friction you need to know normal force and I can calculate it from suspension force. For other points, there is no known suspension force so normal force have to be calculate either out of velocity, acceleration or impact force of the rigid body at this point. I have some ideas but didn’t tested them yet.
So calculating friction at point where sprocket hits something would do the trick for such tank.
But then we left with another issue of maneuverability - tracks going over the curb. Something like Ripsaw has a huge piece of track in front, which helps in scaling obstacle. It helps not by providing point of friction but actually by easing steepness of the curb for the wheel. This I could solve with ether invisible constrained collider (one of the reasons I’m building aerosled, that’s how ski made) or a generated mesh - kind of like virtual projection of the tracks on the surface. I’ll show diagram later.

What you got there looks really cool! I haven’t looked into HD video yet, will check it out later.

Yes, the other package is the one I have and used in unity.

It is also the one where I got the sleep example from since he is the one who made the package and adjusted it for me.

Having the tracks also collide with the ground would be overkill (for me) I do see the problem with the ripsaw.

Is it provided with the full source code? I have suspicion that what they are using for tracks are actually constraints but they are much more stable because they are single plane PhysX constraints and not 6-dof that we are using.

Yes it has full code.
PM me if you want it, I can send you the unity package if you want to study the code.

I’m pretty sure the tracks are done with constraints, since you can also break the tracks when you shoot them… looks pretty neat.
It is however a very recource intensive method and doing it this way with multiple tanks in a scene is not something you want.

In the re-inventing the wheel thread BoredEngineer showed me how he did trailers and now that I’ve found his project whch gives me inspiration and sources for designing blueprinting engines and wheels I’ll be adding alot as my little pet project to do a ue4 farming simulator remake with a couple dozen vehicles is much more viable. Will add on any interesting findings as I’ve always been digging into unreal vehicles but without much success.

It’s ok. To be fair towards other’s IP I can just grab it from AssetsStore. Does it work on Unity free?
Regardless, I don’t think I want to go into physical simulation of tracks as some of other features, such as anisotropic friction, would require quite a lot of re-engineering to implement.

Whole situation with track friction on a sprocket/idler is similar to simulating British Mark-I Tank. There are no suspension springs pushing on tracks, so I can’t use suspension force to calculate normal force. We need to calculate it in a different way.
This is a simple schematics.


Top case is easy. As long as suspension is setup properly it’s force would be approximately equal to the amount of force pushing on the track under this point. The benefit is that we don’t need to know anything about other forces effecting vehicle as long as suspension force opposes them at this point.

Bottom case is where things start to get a bit more complicated. For example, I can calculate how gravity would be propagated from center of mass to three contact points. But vehicle is not effected only by gravity! We have friction which pushes it forward, we can have a collision with another object, we can have some other vehicle pulling it somewhere. So to properly calculate F1, F2 and F3 I need to know the sum of all linear forces and sum of all torques effecting vehicle at least on previous frame.
Which is why I’ve made this request: [Feature request] Is it possible to "Get Force"? - Programming & Scripting - Epic Developer Community Forums
I have zero clue how all of the AddForce() and AddForceAtLocation() calls on physics body can be caught and recorded.

Welcome! Good luck with your simulator! :slight_smile:

You do not want to go the route of simulated tracks.

Another “tracked vehicle” example is this one.

You could call the front one a sprocket and the rear an idler.
The inbetween wheels have almost 0 suspension travel, and the contact point if that front sprocket is at the same hight as the middle smaller “road wheels”

What is the best way to implement that in the current script…? since the sprocket and idler have no collision with ground at the moment.

You could add collision for them but it won’t get you any traction. I got couple of ideas today, will test them over the weekend.

I will implement the undercarriage of an excavator now so we have another configuration to test.

I think that will be an interresting worst case scenario for the sprocket and idler collision test.

I dont want to thread hi-jack please tell me if I’m bothering you. I duplicated your setup on the “Carriage” pawn axis for axis and physics constraint for physics constraint. Its a little smaller but I roughly guessed on the offset between the center of the wheel vs the axle (your axles are 20 units in mine are 5) otherwise everything else is the same, even allowing the Z axis to move for suspension 1 wheel diameter. I checked every setting and the only thing I didnt do was add a physics material to my wheels, but they have custom collission also.

I got to this point. As you can see the actual “Hitch” works perfectly but once I start turning the wheels go bonkers.

I started with just 2 wheels in the rear as I originally watned but it was even worse.
My pivot point is right at the hitch, your carriage bodys mesh “Body” is center-bottom. Could this be the issue?

I’m thinking of making both wheels one whole mesh and then constrainting it to 2 “roller bearing” physics constrints.

As you can see if I can get over the rolling wheel problem I’m off to the races, no pun intended.

The only fix I had was to set the rotation of the axles (the cones) to 0,0,0 every frame but that only allows it to move in one direction, otherwise it stays rock solid. Maybe I need to set their rotation based on the rotation of the body then?

Any ideas would be greatlyt appreciated.

I’m going to post a thread on this too. Thanks.

Edit: I took the above idea and as you can see it works well but any glitch causes it to go bonkers. When driving straight (+x) it seems much better. Do the physics constraints when locking an axis of location/rotation take world rotation into account when turned in the world or is it relative and thus locking/freeing one axis makes it become hte inverse when turned into another axis?

Would I have to have it set which of the 6 constraints are set and when limited by how much when the vehicle goes from driving +X to say +y or -y or -x?

Here you can see the results of setting the rotation to the world rotation of the actor

If you add sockets to you carriage mesh (you can do it in ue4 in mesh manager, just open your mesh asset and socket manager will be at the bottom right corner) then you can constraint your wheels directly to sockets. Axle was necessary just to be able to turn wheels on the truck by turning axle, carriage doesn’t really need them.
When you constraint wheels make sure to allow them to rotate freely in Y axis. I don’t do that because with no-friction physics material wheels are just sliding over the surface.

Seems sick! Also a super time saver for people who want to make a tank (or maybe racing) game! Extra kudos for Open-Sourcing.

I had tried sockets origionally but didnt have much success. Will try again. Ill add a physmat with some friction to the wheels to. Otherwise scale up?

Not sure what you mean. The whole point with sockets is to place root of the constrained mesh as close as possible to a point on which you want to constrain it. This makes it easier for solver to maintain constrain and makes it more stable.
In your first video it doesn’t look like constrains are working at all. Can you show their settings?

Thank you and enjoy! :slight_smile:

1c1d08df32db93da0622ceec9446cd39eba4e6fe.jpeg

This is a very early prototype of Mark-I tank (press 4 to posses):
https://www.dropbox.com/s/g4q8sk7gvf3tc71/MarkI_Prototype.rar?dl=0

It doesn’t drive nicely and has some issues with controls. But the main point was to get custom friction working without any kind of suspension.
Tank can easily get stuck on logs as friction is processed only in selected points of the track. Now I need to figure out how this functionality can be ported to A_TrackedVehicle class for sprocket and idler. There are some other changes to the math behind friction calculation and I need to re-factor few functions to get it working properly.