Building a suspension for the Tank

Hi, i started building a more realistic suspension for the tank:

Features:

  • full suspended
  • collision Bug gone
  • no need for correctional ApplySidewaysForce() anymore
  • can slide sideways and drift depending on the ground materials friction

ToDo:

  • change DriveTrack() from applying forces to the body to rotating the tracks sprocket

This is the current state of development:

4 Likes

Looks good! Can you tell us about your approach?

Sure, please keep in mind, it is still beta state:

How to:

  • first create a wheel mesh of propper size, i used a cylinder shape, remove collision after import and choose a capsule collision and place it.
  • position the mesh correct 2 times in the same place and name them individually, use collision and physics set to on.
  • the first mesh gets collision option worldstatic, all other to ignore (so it can roll on the ground)
  • the second one gets no collision at all ( this is just a placeholder to connect the following constraints, size matters here (or mass maybe, so i just made it the same dimensions then the wheel )
  • connect 2 constraints from the wheel to the placeholder, position them exactly on the axis inner and outer joints of the wheel, featuring NO linear movement and just angular free rotation in the z axis ( should be the last slot but depends on your wheel import)
  • then connect one constraint from the wheel to the tank body, limited Z movement ( i chose 35 cm) and add both linear engines set to on, the top one is the spring rate (12k here), the second one the damping (750) with target value only in z (7-10.)
    -FInally remove the collision boxes on the track-mesh

The 4 lower wheels are suspended, the smaller front one just helps not to get stuck with the nose of the tank.
I used low friction material from the tutorial for both, tankwheel and tankbody.
I spared the small wheel in the rear of the tank, because most of the time the tank touches the ground with the fuel-tanks firrst while colliding backwards.
Use a 260DP collision on the tanks body and just scale it to fit between the tracks.
Reduce force vector ( found on the tracks_mesh ) to aprox 25…(was 40… in the tutorial)
Tanks body has linear damping of .8 to limit speed and a small amount of angular damping

In the code you need to:

  • add the wheels as collision method ( onhit in tanktracks ) or bypass the onhit by calling the Move function directly.
  • spare the sideways correctional force method

Thats it.

And here is an issue with this approach so far. maybe someone finds a solution:
I can add rotation to the wheels (the only part touching the ground) but they do not make the tank move…it looks more like 2 forcevectors nearly equaling each other regarding in a very slow opposite movement.
I have not found a solution for this yet.

Maybe someone has an idea ??

Thats it.

It took me a whole evening to get it running and setup, good luck.

4 Likes

> MAJOR UPDATE

The physics embedding in UE4 is somehow difficult, especially if you work with staticmeshcomponent.
For instance: Constraints jsut change behaviour if you use the initialise function in c code, they act suddenly like loose shackles instead of joints…so i got rid all the blueprint embedding, i just kept 6 sockets with 6 very small static meshes as placeholders for the initialise function.

All the rest is done in

C++ CODE

now. (if you listen closely, you may hear a fine “TAADAAA” here lol)

Here is my current state of work:

Features:

  • 6 sockets measuring their height and the reflecting impact-normal to the terrain with a collision routine (HItResult with WorldStatic setting so far)

Each wheel(socket) calculates a progressive spring rate depending on the hit result, suspension inbound travel and suspension max inbound value.

An additional damping is applied when the suspension has high travel velocity to avoid too much bouncing of the tank after jumping

The calculated force is scaled with a cosine function and a small magic threshold by the impact normal from the HitResult and the rotational offset of a normailzed up-vector, rotated by the tnaks current orientation and then applied to the related socket.

Since i did not get angular movement into the tank (roll & pitch) just by adding force to different socket positions as i wanted to, I calculate an angular force impulse for each wheel(socket) by position of the soket and suspension inbound ratio and apply it to the tank.

  • spring rate and suspension heigt blueprint settable
  • damping for inbound and outbound blueprint settable
  • Any wheel with positive HitResult triggers the DRIVE function on its track side, so no speed can be applied when doing aerial stunts.
  • complete track-section with the hitevent is removed from code
  • the bug with the tracks getting stuck in the terrain and flipping the tank is fixed with this. There are no colliding components at all hitting the ground. If the tank jumps high and lands hard, then the suspension will inbound so much, that the tanks body collides with the terrain, just like in real life.

I am quite happy with the result so far, it needs a bit more tuning etc though.

Next step will be adding friction to the ground and calculating it into the tanks movement to get rid of the ApplySidewaysForce function, which is right now in use again.

3 Likes

> MAJOR UPDATE

…another one…lol

Features added:

  • reworked the tank mesh, removed the wheels and sprocket, centered the mesh, fixed some issues and added a texture
  • 10 wheels, visible, moving and rotating…(what really gave me a hard time), wheel mesh reworkedt & textured
  • 10 x lower damper rod added, moving with the suspension
  • reduced suspension travel maximum and adapted the setup values for a better look and feel
  • all wheels full suspended and propelled
  • suspension damping reworked, feels and looks way better now

Here is the current state of development:

https://www.youtube.com/watch?v=CajXglC_MKE

And this is for the community:

Rotaing something on a rotated object is …hmmm…tricky.

Here is the solution (so spare your time…it took me hours to get this working properly, even though its down to 3 lines of code finally):

//Set the .Roll of the wheel
FRotator WheelSpin = FRotator(-ForwardSpeed + LastWheelRotation, 0.0f, 0.0f);
// Combine Rotator with the ComponentOrientation …order matters: Orignal Orientation * NewRotation
FRotator FinalWheelSpin = FRotator(FQuat(GetComponentRotation())*FQuat(WheelSpin));
//Set the new WheelRotaion
WheelVisual->SetRelativeRotation(FinalWheelSpin);

Quaternions…i do not understand them but i found this in the UE4 maths… and it works!

More to come…

4 Likes

Wow, that looks great! Do you know how you could add a track to the wheels, possibly? I’m just curious

@expertsummer328:
Sure…a complete visual working tank track is the goal combined with as much physics as possible and necessary.

A minor update…

Todday ( after work) i started refactoring my mess and succeded…code is readable again, no function filling more then a screen, unnecessary stuff removed and documentation and variable names make sense now.

@Ben: if you ever read this, i really changed my style in coding, way more refactoring and variables with names that provide understanding of the code in months too…thanks so much for your refactoring lessons

In Addition i added some…

Features:

  • tank wheels rotate now propper doing pivot turns from point pivot to one track at full stop, everything is fine
  • added a position forset to the wheels, at high speed they moved visually back and forth depending on driving forth and back. Could not find a bug in the code, but it looks like the main tank and the wheels as spawned components get rendered at different times in the visual frame. FIxed that by a calculating an offset depending on forward speed vector, i just ignored sideways velocity, cause there is never a visual effect, speed is never high enough sideways.
  • reworked the tanks physics and fiddled around with the suspension settings. Perfomred a hunt with 10 AI tanks and after 20 mins only 2 of them were upside down in a really rough terrain. Thats fine for me.
  • moved the DriveTrack function to the tankmovement component. it checks if one wheel of a track side is touching the ground, if so maximum power can be applied to that side.
  • fixed some minor bugs and todoos in the code, removed almost all magic numbers.

A short current state of progress video:

Stil to come: track visualisation, just looking into splines for realization

3 Likes

Awesome job carrying-on the project while we dream up the next section, a shining example to others.

Thanks for sharing!

2 Likes

Amazing work L-tec. Looking forward to getting through to the end of the battle tank section so I can attempt to implement this suspension stuff. I’ve spent quite a bit of time fine tuning my own non-suspension movement system, and I think I’ve reached the limits of what can be achieved there (by tweaking numbers, colliders, location to apply forces and hacky wheel touching ground workarounds). It works quite well and creates the sort of game play aesthetic I’m after (including drifting tanks in violation of MrT edict)… but no matter what I do, I can’t get it to not snag while going at a fairly tangential manner up a hill (i.e. not directly, but up the diagonal), as well as other little oddities that would prove frustrating to a player not looking to solve a design and coding puzzle.

Once I get it to a presentable state, look forward to showing it off to you guys. I made an awesome Mega and mini turret pair. A mega turret the size of a battleship turret and a mini turret that sits on top of the mega turret to pepper the player with smaller projectiles.

1 Like

Some progress:

https://www.youtube.com/watch?v=GixZ-u2yTXA&feature=youtu.be

Features:

  • Added 13 tracktiles, no circular moving yet while driving forth and back, but got some maths figured out to place and rotate them following the landscapes normal provided by the Hitresult of the suspension code.

Actually i am calculating the tiles direct under the wheels and do some interpolation maths for the connecting ones to place and rotate them correct.
This will be replaced by using a spline, filling it with hitresult for each tracktile and then place the track meshes along the spline. This will finally allow me to do the circular movement of the track tiles too.
Yet a long way to go though… :smiley:

I keep you updated.

1 Like

Minor update

Took me hours to understand splines, Bookwom style in Unrealdocumentation, Answerhub and Main Engines source code.
But got it finally working, makes life way easier with the track tiles :smiley:

New Features:

  • using a spline instead of calculating each tracktiles position and rotation in the code
  • added some more tiles, still have to make the mesh instancing procedural.

A video of the current state of progress:

I keep you updated…

2 Likes

Update

  • it rolls:
3 Likes

This is turning out awesome man!

@RyanPalmer: thanks a lot mate.

Major Update

This is what i got to work this weekend:

Looks abit similar to what you have seen before, but instead of ugly replicating Meshcode, i have managed to make my first C++ procedural Pointer-Array based Meshgeneration, Animation and Positioning method.
In addtion, the spline is now a real loop. Sounds easy, but gave me a hard time to implement correctly with hours of viually debugging the whole method. The Bug-Solution was in one of the last lines of code, a very very nasty typo error interferring with the second spline. But at least, i solved it, one more bug is wiped out, learned a lot about splines and had some fun too.

So now, with a second spline, i spawn 96 tracktiles like nothing, in addition its now about 350 lines less code, all refactured and pretty readable.

For me, this is a major achievment in coding with UE4.

Just for fun: A 100 tracktile whirling centipede whatever…lol

@Ben: I found a major bug in the Tankmovment for AI Tanks. I am not sure if it was mentioned before. I will make an extra thread/post for it the next days, sorry for the delay, but i need to get some sleep, work starts early tomorrow.

5 Likes

Solid stuff! I shall have to investigate these splines…

Thanks L-Tec, for the initial how to you posted a couple weeks ago.

Was actually kinda hard to figure out… but wouldn’t have figured it out at all without what you posted there!

Few things for anyone else trying to implement a basic physics constraint style suspension following along with L-Tec’s pointers:

Don’t parent the wheels to the constraints. Constraints and items that they’re constraining on should be on the same level.

Set the components to constrain to via component name (drop down box, then fill out the text box… no selection menu, no drag and drop - just click on the components, F2 to rename, ctrl+c to copy and ctrl+v into the constrain text box).

The wheel object should only be scaled uniformly. Scaling it non-uniformingly creates a strange bug where it disregards the collision mesh… i.e. you can’t use a sphere and scale it into a disc. Unfortunately.

Most importantly, the wheels need to be set as physics enabled. Counter intuitive if you haven’t been told - because doing it with non constrained objects will cause those objects to fly off from the tank! In retrospect, that makes total sense, because those objects aren’t constrained.

The other bits can be played with to your hearts content, because it’ll actually work… if it doesn’t, then tweaking those numbers won’t do diddly squat! :stuck_out_tongue:

Update

Complete spline track working now.
Everything you see is spawned procedural, Number of Wheels, Number and width of tracktiles to use per side, Position of Front and Rear Wheel/Sprocket is settable, suspension is settable with almost all values via Blueprint.

Next to come… maybe traction and friction or other stuff not sure right now.
I will keep you informed.

@Zaptruder: Cool that i gave you an initial hint how to start, looking forward to your creations

2 Likes

Visual Debugging the ranged Collision method of the track:

2 Likes

I’ve uploaded a new demo! Features the bouncy suspension from your first post - works reasonably well, although I see from your posts, I have a significant journey ahead of me to implement moveable animated tracks. Give it a shot, let me know what you think :slight_smile:

Your track updates are looking pretty mega btw. Glad to see that I wasn’t the only person taking the line trace approach to determining collision.

Privacy & Terms