RTS Car & Tank movement, need serious advice on that one.

Hello everyone.

I’ve been developping an RTS for a while, and I’ve come across a huge issue : vehicles.
Now, I’m starting to understand why every RTS pack and all tutorials I’ve ever seen on UE4 only deal with infantries, and why RTS die during the process…
I’ve seen a couple tutorials and struggled with the problem myself to come to the conclusion that doing AI for vehicle in UE4 is cumbersome to a very unhealthy point !

The problem

So I’m trying to do a Right Click Move To kind of movement for vehicles. It works perfectly fine with Infantries but it is a real clusterf*ck for vehicles…
What I’m trying to archieve is a car/tank able to :

  • Do a U-Turn in a very small area (or on place if it’s a tank).
  • Follow the ground correctly (wheels or/and tracks).
  • Brake within 1m (really fast full stop).
  • Full stop even on a sharp slope (almost ignore gravity - very powerful brakes).
  • Can work with both wheeled vehicles and threaded vehicles.
  • Send minimal datas over network (Client-Server).
  • Capable of huge acceleration & deceleration (in addition to powerful brakes).
    Typically, I’m trying to archieve an AoW, AoA or C&C Generals kind of vehicles.

What I’ve tried

I’ve tried 2 different ways, both currently in a dead end, but both partially working…

1. Using Vehicle Component

The first thing I’ve tried was obviously to use the vehicle component. But :

  • It is overkill : lot of physics, gear system, etc, which I don’t need. All I want are the wheels / track to follow the ground and acceleration/deceleration.
  • IA MoveTo isn’t implemented by default like for infantries.

So of course, I’ve worked on an AI which work with the **Find Path To Location Synchronously ** node.
The hardest part for that version of the algorithm is to control the vehicle. I really don’t understand how and why, but this car is rolling on oil/soap all the time.
I need it to brake fast, and handle the road like a 4x4, turn super quickly, accelerate and decelerate like crazy. Even if it’s not realistic, this is what I want.
And this is the exact opposite of what this car is doing. It takes ages to brake, turn slowly, drift like on ice, etc… I don’t want it to drift AT ALL ! T_T

2. Using Character Component

The second way, of course, was to use character component. So the idea was to replace the mesh of the soldier with a mesh of a car, and use a Physics Constraint to allow the car to rotate to follow the slope.
Does it work ? Yes, and no. As you can’t change the root component of the character and can’t disable it’s collision without the capsule ghosting throught the map, this is really hard to archieve something great.
So I tried to give it some Z freedom, with like 50 units. It works, but when the caspule stop, as AI ignore deceleration, the back of the car jump like it just crashed into a wall. It is probably normal since the speed goes instantly from 600 to 0.
I’ve tried implementing some deceleration but on a 2m length, it won’t help, the car still jump. If I disable that freedom, the car cannot follow the ground correctly because of the stupid capsule component…

Your move, community/devs !

So here I am, in a dead end with 2 semi-working things. I am confused on which way to go, why, and how.
I’ve been stuck on that for a whole week, trying to figure out how to deal with it.

Another problem are the wheels. I don’t know how to deal with steering the wheels (with Char Component). I don’t even know if the wheels should be part of the skelton or separate meshes.
I’m looking for a way to make it work with both wheels and tracks (for tanks).

I don’t need the physics to be perfect. If the wheels are just here to add realism and do not provide any torque, I’m fine with it as long as everything I asked for is respected.

Any help / experience is very well welcomed.
Thanks !

I’ve made some tests in the vehicle template and I just can’t get what I want. Whatever the parameters I use, the car use physics so hard it is getting annoying.

Here is an example of what I want from Act of Agression :

The car was going full speed and I told it to go behind, so it turned within 0.1 sec without losing much speed on a super tiny distance, no drifting, no physics clusterf*ck. It just turned well (unrealistically, I know, but this is what I want).
You can even see the car is doing some crazy stuff because of the brutal speed/direction changes. This is some tweaks to do, but this is really what I wanna archieve.

For now all I have is a car that takes ages to go full speed/brake even with 1 gear and a crazy torque/RPM, that roll on soap and can’t turn at high speed even with stiff set at 900K and steering curve at 1.0 all the time.
Why can’t I get a physically inaccurate vehicle, is that too much to ask ? :frowning:

  • Really fast acceleration/deceleration (go full speed / full stop in 0.1/0.2s).
  • No drift at all : perfect road handling.

I’m not sure about this, since i have not used the vehicle physics yet. But i know i will have this issue too in the near future.
Would probably try to work with the pawn base class and try to implement a “simple” vehicle logic with a few rules. Easier said than done, i know.
I think i have a bit of codelogic when i was working with another engine that implemented acceleration and friction. Maybe i can dig it up later.

Regards

The problem is that you have to replicate everything. And replication is really, REALLY annoying when you do it by hand without using traditionnal pawns. This is the problem with UE4, I feel like if you try to do something different from what it is intended for (FPS/TPS games), it really gets frustrating and cumbersome.

I really wish a dev could answer this thread with an elaborate way to solve this (and a tested solution for vehicle movements (I’m taking care of the pathfinding, of course !)), so at least I could have somewhere to go without running in a dead end after hours of coding. I tried again in a throw away project, and it seems almost impossible to have such a brake/acceleration. I tried having a brake of maximum value, and I still need a long distance to brake (nothing close to my 1m SuperBrake), same for acceleration. Not even talking about the road handling that is WAY to realistic to do what I’m trying to archieve.

I feel like the overall UE4 implementation of things is not using enough inheritance. I wish there were something before Character or Wheeled Vehicle… Right now it’s either all or nothing, which is stupid IMO with the possibility offered by inheritance. You either have a fully operational super sophisticated car with network replication, OR, a Pawn, that doesn’t do anything, not even replication. For a game that will contain 500+ units, I’m pretty sure the network is super happy to broadcast all those useless informations…

If you got something working fine with multiplayer I’m really interested, :slight_smile:

Using physics for this sounds like a huge overkill. Not only it can kill your performance, you would have to “design” vehicle to behave as you want while still adhering to the physics simulation. Custom kinematic implementation would be better suited in this case. You can add a bit of custom physics to it for “flavor”.

There were similar question just few days ago on the forum. With a link to an article of how networking was done in planet anihilation.
I haven’t read it but what I understood all simulation is done on the server and only Transforms and velocity is replicated. If you want to add on top that visible “suspension” it could be done on client side, it won’t generate any forces, just few raytaces to position wheels + some other animation like wobbling anthena or passengers of the car moving by inertia.

This was a thread of mine, and I’ve read it :slight_smile: It was really interesting with all that curve system. But I’m afraid that’s far from doable for me right now, and is not exactly what I’m asking for. For now, I can’t even manage to get a vehicle to do what I want, here is the real issue. With UE4, I’m stuck with either using a vehicle full of physics that can’t even do what I want it to do, or a character that has this stupid capsule component that gives my vehicle a hard time. The worst part is that the character component is closer to my goal than the actual vehicle component !

I thought about the raycast already but I’m not sure about the efficiency. That’s 4 raycasts per vehicle, up to 8/10 for tanks.
I’m starting to think that raycasting is the best solution, but I’m not sure how good it is for performances.

look at “Adding realistic turns” section:
http://www.gamasutra.com/view/feature/131505/toward_more_realistic_pathfinding.php?print=1

the guys making Company of Heroes used this article to implement their vehicle movement.

there is also a link of the sample application with source.

I’m in the same boat, also making an RTS game with vehicles. I’ve actually had some basic success though using nav mesh. If you want, I can share some of my code although it’s farrr from perfect. I use the nav mesh to generate the path, pass a shared path reference to the Pawn, and follow it using a tick function. Then (unfortunately) I use traces on each corner of the vehicle to test for collisions, the traces point in the direction of the wheels. If one of the left side traces hit I steer right, and vise versa. If both hit while reversing I override the drive to forwards. Ect…
I did some physics to come up with a braking system, which allows me to set a specified braking time.
Also I use the SimpleWheeledVehicleMovement which allows me to specify angles for steering and torque for braking and accelerating which helped a lot.

The buildings affect the nav mesh but other vehicles do not. Also NavAgents per vehicle don’t work so this is what I did to avoid more dynamic obstacles.

Still, there’s a few situations where it doesn’t work, the codes a little messy too but if you want to PM me I’ll share it with you