Download

Flying Vehicle with Landing Gear - Physics Object. Help / Advice Please!

My team and I are making a Space Shooter game. It will include 1 manned fighter ships similar in scale to modern day jet fighters. IE the same size as an F-15 or F-35.

So I have built these space fighters as skeletal meshes because I want them to have various moving parts. primarily an animated Landing Gear and a Cockpit Canopy that opens and closes.

So I have a few of these ships built and the animations all work fine when viewed in Persona.

However, I am having absolutely no joy with constructing the Physics Asset for these ships. What I really do not understand is how to achieve my desired result using PHAT. So let me explain exactly the kind of behaviour I am aiming for.

So the spaceship should have 1 single primary collision body that neatly encompasses the ships hull. Now in PHAT, thats all fine, if I have a skeletal mesh with just 1 collision body, everything is fine. However the ship needs to have a couple more collision bodies for the Landing Gear and Canopy. To make it simple lets just talk about the Landing Gear.

In PHAT when the Landing Gear is in / retracted, the ship should fall to the ground and land on it’s belly. Like this: ConceptShipPHAT_001.PNG
Lands on its belly: ConceptShipPHAT_002.PNG

But when the Landing Gear is out it should behave like this: ConceptShipPHAT_003.PNG
Fall to the ground and land neatly on it’s Landing Gear, like this: ConceptShipPHAT_004.PNG

And also theoretically, if the ship lands on it’s belly with the Landing Gear in, but then lets out the Landing Gear, the gear itself should push into the ground pushing the ship up and setting it on to it’s Landing Gear. That’s how I imagine it working any ways.

Sadly however, I have not been able to achieve any of this functionality inside PHAT. The main problem it seems to me is that what I am wanting is for the main ship collision object to work with “Default” Physics type in PHAT, and for the Landing Gear objects to work with “Kinematic” or “Simulated” (Not sure which). Because “Kinematic / Simulated” is the only way to have an animation play on the Physics object.

However if I set the bones like this, with the ships main body as “Default” and Landing Gears as “Kinematic” and try to play the anim, the whole thing just flys off the screen at a 100000mph.

I know exactly what I am trying to achieve, but really no idea how to achieve it. I have read all the PHAT documentation I can find and watched the PHAT Tutorials. But none of these really help.
Essentially what I am trying to do is have an animated object (Part of the Skeletal Mesh), IE the Landing Gears attached to the main ship body and animated and have them all have proper collision. But so far I cannot work out how to do it.

It seems to me a fairly simple goal, yet the implementation seems impossible.

Any advice or suggestions on how to set up my ships to achieve the desired effect would be most welcome. Thanks! :slight_smile:

I remember having exactly the same problem in UDK. I had a small lander module with retractable landing legs and it worked fine except cases when landing legs collide while retraction animation plays, same issue - choosing between kinematic/simulated states.

First check your collisions, make sure there is no collision between kinematic body and the rest of the ship.

If that doesn’t help you could try following, it might not work with PHAT but you can make it using combination of skeletal and static mesh components with constraint components in blueprint:
Keep your landing gear as simulated all the time. Use linear drive of constraint to simulate hydraulic force on landing gear. So that it will keep your ship straight when landed, which mean that linear drive force should be strong enough to handle it weight.
When you want to detract your gear I see two options:
Option A: Slowly change target length of linear drive, just make it shorter. If you gear consists of multiple pieces, do it for one at a time.
Option B: Slowly add a local force vector to gear (pushing it into retracted state) and change parameters of linear drive to less resistance. You have to balance this very carefully so that force is not transferred to ship itself.

In any case you need to make sure that there is NO collision between your pieces of gear and ship itself. Collision doesn’t propagate with children, so ticking “Ignore Collision” on constraint between two bodies won’t help if you have something else connected in chain. For example, tube of landing gear is connected to ship and landing leg is connected to tube, even if your constraint ignore collision between tube and ship it won’t ignore collision between leg and ship, which can lead to hilarious behavior. In such cases you have to remove collision on a level of collision channels between objects.

Check mass of all pieces, in many cases I had to override mass and make objects heavier or lighter to get a proper interaction. When mass of the constrained objects is too different behavior of the lighter one can become very chaotic.

PS: You don’t have to make your plane as skeletal mesh to have some moving parts like canopy and landing gear. You can assemble everything as a hierarchy of static meshes in blueprint, connected by physics constraint components. I find this approach preferable in many cases as you can have much more detailed and exact collision mesh on each of your parts. Another benefit is that you can always “lock” pieces into place by disabling constraint and attaching objects.

Hi Bored Engineer! :slight_smile: Thank you very much for your detailed and informative reply. Your advice is really helpful!

You are right that I could achieve moving parts to the ship using Static Meshes and this is certainly an option. The only problem is is that I was aiming for a certain level of complexity / detail in the moving parts of the Landing Gear and Canopy… Rotating Joints, Extending Levers etc etc and although it is fairly easy to make such animations with a Skeletal Mesh inside my 3D software (Blender 3D) setting up such complex machinery as Static Meshes in UE4 would be a massivly complex task. So if I am going to use Static Meshes animated in Blueprint, I may indeed have to aim for something a bit simpler. It’s a good suggestion, thanks!

With regards the level of detail of collision (Convex Hull) objects between Static and Skeletal Meshes, you will be pleased to hear that I recently discovered that you can in fact create custom collision objects (UCX) for Skeletal Meshes. If you create the custom collision inside your 3D program, in the same way as creating custom collision for a static mesh, and then import that Static Mesh and it’s collision into UE4. You can then assign that custom collision object to a particular bone inside PHAT. This process is described in the advanced Vehicle Tutorial found here: https://docs.unrealengine.com/latest/INT/Engine/Physics/Vehicles/DoubleWishboneVehicle/index.html#phat

So I will follow the directions you have outlined above with regards collision between objects in PHAT. Perhaps that can go some way to solving the issue and achieving the desired results. Thanks again BoredEngineer. I will let you know my results! :slight_smile:

In this case I might try using skeletal mesh in my current setup. Right now I have a 12 wheeled sand crawler which moves similarly to tank. Suspension is done using physics constraints between static meshes. Yesterday I found a bug where wheels origin could flip into some weird position just because it hits landscape too hard. Which flips up vector to some random rotation and makes some of my calculations irrelevant.
You are right, if you have a plenty of kinematic animations then skeletal mesh might be a better option, my worrie is that you won’t be able to adjust constraints outside of PHAT editor. I don’t remember if I was able to do in UDK.

I did some additional tests this morning and I’m getting a bit ****** at how constraints are working. I can’t find the way to make them really rigid. I understand that having a completely locked constraint is not the same as completely welding two bodies and there will be some inertia passing from object to object but I would expect at least some sort of stability. I’m thinking about ditching constraint all together and writing all the math myself. So that suspension is build similarly to how Physix handles car suspension, using raycast and applying suspension as a physical force. At least this will lock wheels into their **** position where they suppose to stay.

Hey again Bored Engineer. Yes I am also frustrated by the inability to have a completly fixed constraint. For example the Landing Gear of my ship should be essentially rigidly connected to the ships hull, there should be no movement between them. except in the lower suspension. And yet even locked constraints seem to wiggle about. Oh well, we keep experimenting! Goodluck with it. :slight_smile:

So this thing has some insights on why it’s happening:
https://developer.nvidia.com/sites/default/files/akamai/physx/Manual/Joints.html
I’m going to give it a second try and perhaps re-arrange my setup. What Physx manual says is that you can combine kinetic and simulated bodies but hierarchy of connection is important. Kinetic body have to be a parent not a child. So I don’t know how you can connect it to a root body unless you actually weld it as a separate object - you still can animate it even if it’s welded. The other consideration is mass, the least mass difference between elements the faster solver can converge.

Okay, good research. Thanks BoredEngineer! :slight_smile: This sure has turned out to be a pretty complex problem. But if we can solve it, that would be awesome! :smiley:

After various experimentation - I have come to the conclusion that using PHAT to try to simulate this kind of Physics behaviour is probably not the best method. And that using Blueprints is probably a better idea. But I still have no idea how to actually do that. Could anyone point me in the right direction please? Thanks!

It’s been a while since we discussed this and I think solution is rather simple. You can add constraint component in blueprint and then dynamically control it from there. More specifically when you enable linear or angular drive, which you need to imitate suspension, you can adjust their target position using nodes in BP.
I’m using this method to steer front ski of aerosled, by simply adjusting their angular target from user input. I’m in the process of reviving my PC, so can’t post screenshot but you can check how it done in my project on github (link in first post of signature) look for Aerosled blueprint in Content->Blueprint->Aerosled folder.

Even complicated animation can be done like that as you can drive target of drive using timelines or matanie, as long as you can get a simple float or a vector as output.
Regarding stability you have to tweak mass of your parts. Their relative mass should stay in 1-10 range, the smaller the difference the better, it’s easier for solver to maintain constraint this way. Worst case scenario you could play with the mass of your landing gear only when you extend it. In order for it to work you need to disable physics on landing gear first, change its mass and then enable physics immideately again. Someone reported that this works but I’ve never tried it myself.

Hi Bored Engineer. :slight_smile: Thanks so much for offering a solution to this issue!

I am a 3D artist, so much of this “Programming / Blueprinting” stuff is a bit of a mystery to me, but I understand the basics of what you are suggesting. I will try to use the method you have suggested. Thanks very much Bored Engineer.

Also, I just wanted to say “sorry” to you. Because you wrote me a nice message a few months back but I did not reply. Sorry about that. I’ll try to reply soon. Cheers! :slight_smile: