Difference PhysX betweeen Unity and UE4

Hi!

Long time user of Unity here, but we are looking into switching to UE4.

But we are having problems with the PhysX implementation in UE4, specially regarding Constraints.
We dont have these problems in Unity which also uses PhysX, but there seams to be differences in the implemention.
We are trying to create an Wheelloader with hydralics and articulated steering which works perfect in Unity using Configurable Joints.

The first problem is that, you cant have locked Anglular Axis, and a motor at the same time…If we want a simple powered one Axis Hinge, we have to set the non movable Axis to Limit with 0 limit instead of Locked. Which as far as I know has to do with SLERP drive instead of “Swing and Twist”, correct? But still strange. BTW is it possible to change this via Blueprint?

The second problem is that the above type Power Hinge joint, cant hold its position after Angular Target Velocity input is for ex. X. In Unity the Maximum Force value creates resistance in the joint at Hi values, so the joint stay in place even if velocity is 0.

When searching around in the forums etc, I get the impression that the physics in Unreal are more or less only tested and used with rag dolls and collisions. There are no examples of physX vehicles, exept the new Vehicle template, but since we need hydralics, cranes and other custom vehicle thats no use to us unfortunately.

Thanks for any help, we really like UE4 and would like to make a switch, but right now this is one thing that is stopping us :frowning:

Hi MrPure,

You are correct about us using SLERP instead of Swing and Twist. I’m going to look into exposing this as an option right now.

I’m not sure I understand the second problem. Could you explain a bit more? Do you mean that the velocity setting is preventing the motor from maintaining position? This is the behavior I would expect if you are using a very small velocity setting. Note that the UI is slightly confusing: 0 value will be interpreted as turning off the constraint.

We are pushing to have more testing done for physics. Do you have any cases in particular you’d be interested in?

By the way have you checked out the vehicle sample game? It’s still a car setup, but the tuning is quite different than the vehicle template.

Thanks for bringing this up, please let me know if you have any more questions or concerns!

Hi Ori,
Thanks for your quick answer, means a lot!

Background:
I have included two pictures of this test project, as you can see the vehicle is an articulated “Wheel loader” that diggs and load rocks on Trucks etc. In these kind of vehicles every thing exept the wheels are driven by hydraulic pistons, which do not return to their initial position after input, but increased and decreased so to speak. A regular Hydralic piston would be simulated by a Linear Constraint that are locked in all access exept one which is limited. This could then be positioned in different position by using Velocity (relative) or Position (absolut). But the important this is that when you have set the piston in a position by Joystick or key you want it to stay there, eg. Move the Bucket of this loader up and have it stay up.

If we now look att the Articulated Steering Constraint shown in the pictures, it should work the same way. We rotate the “hinge” to a disiered turning angle by using velocity and then stop the input. Now we want the steering to stay in that angle until we turn again. As it is now the Constraint is loose when velocity is 0. We basically want to add a lot of resistance to the joint when its not supposed to move.

You mentioned your vehicle sample template. Would it be possible to in some way modify it so it can be used for this kind of vehicle? Basicly to be able to split it in two to add a joint between, and also add other physics object with constraint (as a boom and bucket or perhaps a physics Gun turret :slight_smile: )

Long post, but hope you understand more now what we are trying to do. :slight_smile:

Pictures

BluePrint of the Input

Ok, I think I’m understanding this case a lot better, thanks for the background it really helps.

I’ve locally added the option to use twist and swing and I’ll be submitting it shortly so in theory it should be out in the 4.3 release.

As for using velocity of 0,0,0 - I’m not sure if this would give you the correct behavior because the velocity motor will only reduce the speed, it will not actually keep the object at its original resting place. So in the case of 0,0,0 you will have some slight drift because the velocity motor will detect an increase in velocity (maybe due to gravity) and then it will correct it by reducing velocity down to (0,0,0).

A solution for the 4.2 build is to use the orientation motor. You’d need to set the target orientation to the current orientation, which would prevent the drift. This is not a great solution though because having to calculate the orientation can be cumbersome. I’m going to expose some functionality into blueprint so that you can turn angular constraints on and off (which would work with the Twist and Swing approach) as well as a way to get the current orientation and position so that even with SLERP you could at least freeze a motor in its current position. I’m going to do this now so that it’s in 4.3 - I’ll keep you posted.

Let me know if this sounds like a good solution for you or if you have any other concerns about constraints/physics

Thanks again!!
I hope the “Swing and Twist” will work much better, I´ll let you now. We have build from the source code, so could we try this before 4.3 release?

Will this be possible:
You mentioned your vehicle sample template. Would it be possible to in some way modify it so it can be used for this kind of vehicle? Basicly to be able to split it in two to add a joint between, and also add other physics object with constraint (as a boom and bucket or perhaps a physics Gun turret :slight_smile: )

Regarding switching between Velocity and Orientation, we actually do that in Unity :slight_smile: since as you said, it is not 100% reliable with just Force.
This is the Javascript code in Unity we use, don´t know if you can see if it is possible to do this in blueprint?

function FixedUpdate() 
{
	if (velocity == 0){
		joint.angularXDrive.mode= JointDriveMode.Position;
	}
	else{
		joint.targetRotation = Quaternion.Inverse(parentObj.transform.localRotation)*transform.localRotation;  *//Using an Hinge w Angle readout //joint.targetRotation = Quaternion.Euler(-jointHinge.angle,0,0);*
		joint.targetAngularVelocity = Vector3(((velocity * -speed) * Time.deltaTime) ,0,0);
		
		joint.angularXDrive.mode= JointDriveMode.Velocity;
	}

If you’re using source you should be able to grab my change off github once it’s been submitted (most likely before the end of today).

The change is self contained so it should be fine to just grab it on its own (I’ll post link once I have it up).

In the javascript example, wouldn’t you still need to set the angular position for the drive? I think it would be possible to do all this in blueprint. I’m setting up a test map which should do the desired behavior so I’ll post a screenshot of my blueprint

About vehicles: I think it would be possible as the vehicles are already using multi bodies. Essentially the vehicle simulation code just computes the forces to apply to the chassis of the vehicle based on tire/engine settings - in the sample game we have a simple antenna which is just attached using a constraint.

I haven’t actually tried something like this, but I think it should work and I’d be interested to see it. One issue you might run into is related to the mass difference between the car’s main body and the attachments. In the antenna case we had to make the antenna’s mass much smaller than the car’s because otherwise its movement would affect the way you steer. I think there are a few ways you could solve this though depending on your game.

Does that make sense?

Yes thats what this does, I think…:
joint.targetRotation = Quaternion.Inverse(parentObj.transform.localRotation)*transform.localRotation;
which actually is run when in velocity mode.
Its confusion since Unity has different naming of the parameters then I think UE4 and nvidia :wink:
But it would be great with a Blueprint screenshot, since we are kind of new to blueprint, but we love it!

I will look at the vehicle example, to see if we can use at least the Wheel and drive system and attach them to an Articulated Chassi…

UPDATE: The twist and swing change is available here:
https://github.com/EpicGames/UnrealEngine/commit/6568f9c9a63f4f6b6ea6b2deaf60091bd8084468

This might be helpful:

So I’ve got a nice example working locally. I have a box that has an angular velocity motor driving it. When I step into a trigger volume it will freeze it where it is. When I leave the trigger volume the orientation motor is turned off and velocity turned back on.

While doing this I noticed that the constraint blueprint for setting orientation target used a quaternion instead of a rotator. This CL fixes that:
https://github.com/EpicGames/UnrealEngine/commit/9dc4434ab9aabe28820a3cf26f0177ce70844eda

Here’s my blueprint setup. I’ve setup the constraint as the root which makes getting the cube orientation easy:

If you could play with these changes that would be great as it would give us some good use cases that we haven’t necessarily run into yet.

Thanks for all the info, I think it’ll really help motors in the long run!

Now the Constraints work as in Unity!! the Swing and Twist did it :slight_smile:

One small thing I noticed was that you added or renamed Angular Spring and Damping to “Angular Velocity Strength” and “Angular Velocity Strength” correct? Angular Velocity Strength is very valuable as a “Brake” and to roughly hold it in place. But how do I access it thou blueprint? is it by the old Spring Damping or ?

I will try to make a Position and Angular joint switcher later.

But Thanks alot for your help, really impressed by the support!!

The old Spring and Damping will point to the same thing. I need to rename that as well.