Preventing Angular Motor Rotation of axles from rotating entire vehicle

Good afternoon,

I am in the infancy with my unreal skills and project overall.

I have a Mine cart that I am trying to move across some rail s

Requirement s:

As realistic as possible, no spline/timeline followi ng.

The cart has its Body, Axles, and Wheels as separate static meshes that are held together with Physics Constrai nts.

Problem: The rotation torque of the Angular Twist Drive is causing the Mine cart itself to flip. I have played wth various sizes of forces and the cart will ei ther:

  1. stand still (not enough force to overcome weight and fri ction)

  2. Do backflips, even if VERY slowly

I disabled gravity on all static meshes and the cart does backflips in place with the wheels r otating,

Attempted s olutions:

  1. Lower COM to - 50 to -100

  2. Cart mass 3000kg

  3. Axles 300 kg

  4. wheels 100 kg

  5. Reorganizing static mesh/Physics constraint hierarchy so Physics Constraints ar e not parents.

  6. Physics Material on the wheels - f riction 5 to 10

Ill include some ph otos and videos.

I can get the desired outcome using a crazy high number like 100000000 in “add impulse” to the forward vetor of the mine cart. But I want the drive to be derived from the a xles of the cart.

Chat GPT says the sytem is “too perfect”, not enough give or something, i dont a ccept that answer.

Side note: I am aware of the chaos vehicle system but cant for the life of me get the skeletal mesh of a static mesh imported from blender in unreal.

Any ideas? Photos and videos are attached.

Mi necart Heiarchy

I would post a video but the forum isnt letting me, also cant post more than one photo.

So as i understood you are doing a full physics simulation, vanilla without anything (Correct me if I understood it not correctly).

Thats ok should work.

1 - First things first do enable gravity on all simulated physics bodies.
Not because gravity is required for the cart to be balanced, but to keep the system consistent with the world forces. If gravity is disabled the constraint motors and torques can behave a bit misleading since there is no constant downward force.

2- Make your chasis fully aligned in positions relative. Thats important for overall stability.
Ex :
WheelFR( 100,50,0) - WheelFL (100, -50,0)
WheelBR( -100,50,0) - WheelBL (-100, -50,0)

MineCarts Static Mesh origin is 0 ,0.

3 - Designate the main carts CoM as center of mass of all simulated bodies. Since you are using pure physics bodies (body + axles + wheels) its generally good if the overall center of mass ends up near the middle of the cart and slightly lower on Z for stability.

Example : if your cart body relative position is (0,0,0) and your WheelRight position is (100,50,0) then overall mass distribution should still keep the center around the body and not drifting too much to any side. A slightly lower Z center of mass usually helps stability.

Since this is a mine cart the system should be fairly stable if wheels have a decent edge collision and a medium friction and damping on the physics material.

4- Make a singe force applied for movement. Since this is a mine cart it can only pushed or pulled. Designate a force direction (ActorForward) x ForceScalar and maybe lets do with impulse.

Location = ActorLocation  + ActorForward x Distance
// Apply forward or backward slightly outside of the cart. If cart length is 100 then 101-150 should be fine. Negative number if pull so you pull from behind lowering torque, pulling with a rope / lazy move)
// Location = ActorLocation + ActorForward x 150

TargetImpulse = ActorForward x ImpulseStrength
// Try and error could require a big number but something makes sense.

OnTick->AddImpulseAtLocation (Location , TargetImpulse)

Using angular forces on wheels is something different and requires a different logic. If you apply torque on the wheels through constraints, remember that the torque you apply on the wheel will also be applied back negatively to the parent body (the cart) because of the constraint. So the system will try to rotate both bodies unless something counteracts it. For every action there is a reaction so to nullify that reaction you have to manually add counter forces on parent body. If things balanced very nicely sometimes even that is not required but if torque is minor masses are already overcoming that issues (Wheel of a locomotive). For those you can use force limits on the contraints also contraints parent dominates bool kinda works sometimes.

Chaos vehicle works on this principle so its more accurate in terms of force application. However for a mine cart you might also want to consider how these carts usually move in reality. They normally dont steer and dont have motors, they are generally pushed or pulled, so sometimes a single directional force can be enough depending on your design.

Apply these forces on tick, preferable you can make interpolation of forces gradually increasing
FinterpTo ( CurrentImpulse , TargetImpulse )

5- Adding additional forces on the vehicle : As I understand you are making an anti roll torque on vehicle. If thats the case try to scale this forces by vehicles lateral velocity.

If the game is more arcade like and there are turns, loops or you want to keep the vehicle on the tracks you can also consider some spoiler type force pushing the cart down. This is not really to fix backflips but more like an extra stabilizing force.

Depending on the game this can be a constraint which i dont like because it feels like artificial gravity. I usually prefer using an angle approach.

Simply get the lean of the vehicle against world Z (default gravity) and scale the spoiler force with the lean. The more it leans the stronger the force pushing the cart down into the tracks.
Example :

OnTick->AddImpulseAtLocation(ActorLocation, Dot(ActorRight, FVector(0,0,-1)) * SpoilerForce * ActorUp)

You can play with spoiler force x speed and direction this can even when correctly calculated can keep vehicle upside down for a while if you have loops :slight_smile:

Let me know and would be great if you can put some more screen shots.

Thank you for the quick reply.

I would post more photos/videos but the forum only allows me one photo per post because I am a “new user”. If there is anyway you can change that please do and I would be happy to give you every detail in a single post.

  1. I had disabled gravity on the mine cart body in order to better see the torque being applied to the cart, it will be enabled for the end concept
  2. All placements are of wheels and axles are correct/ equal distance from cart origin
  3. I lowered the COM of the wheels and axle of to match that of the mine cart and the instability grew, the cart “dances” lol. (Let me know if I misunderstood your instructions)
  4. I will save your Impulse equation in my back pocket, I would like to get the movemnt form the axles solved because I eventually want to derail the trains and dont want to include a calculation to determine whether all wheels are in contact with the rails → then apply force.
  5. With the addition of forces, the idea is similar to 4: I want to derail, and fear that adding forces to counter axle rotation could inhibit that.
  6. I Enabled “Parent Dominates” on the Physics Constraint but the cart just sat there, no rotation or anything interestingly enough

I think you hit the issue on the head:

I believe the question is, how can I nullify the “negative torque” being applied.

A possible solution: Perhaps the wheelbase is just too short for this type of tourque -

It is only 70uu so maybe if I applied this Anuglar Motor to an acutal train engine/locomotive with a larger wheelbase I wouldnt have this issue?

Currently testing this with a static mesh of the cart the is scaled out 4 times so the wheelbase is 700 nstead of 70 but the cart is freaking out/breaking and will require further investigation at this time.

I will also play with angular dampening on the mine cart main body

I would like to upload a video of the current performance however, when attempting, the system says “Sorry, new users cannot upload attachments” (I am allowed 1 photo tho, if you can change/fix please do.)

Here is my one allotted photo: it is of the angular motor logic.

I hope you can zoom in on it:

Please let me know if any other details you require.

And thank you very much for your expertise.

Thanks for confirmation of the points. Thosse need to be done in the fist place generally that why mentioned those since It would lower debugging effort and actually delivering something works fine.

I lowered the COM of the wheels and axle of to match that of the mine cart and the instability grew, the cart “dances” lol. (Let me know if I misunderstood your instructions)
This is interesting to be honestly but lets leave it to the side for now, if center of masss (Com) is in meaningfull place, mass of tires are lower thaan actual body chasis, it shouldn’t behaave crazy this tells me there could be some scaling problem on overall setup but lets move for a second.

So lets focus on doing forces from the axle side as you describe maybe if necesssary wefocus on applying counter torques. Angular motor reaction torque is real however before we diving into that solution with respect I preferr to diagnose why it happens. That would be the sane path to move.

So Before diving this really suspicious.

I Enabled “Parent Dominates” on the Physics Constraint but the cart just sat there, no rotation or anything interestingly enough

That also gives me a lot of possible scenarios. So once the parent stopped absorbing / showing that reaction, the remaining motor output may simply not be enough to overcome: There can be a lot of things when parent dominates however complete stop is not something i would expect

  • Can be cause of wheel contact shape Collision shape
  • Very big mass or inertia, very high friction coefficient maybe with static even.
  • Or misconfigured constraints.

Since with some setup the wheels atleast should try to turn. Please do check these (as checklist again). A quick test I would do :slight_smile: put cart upside down and examine if there is any movement available. Atleast try try attempt to turn or struggle. Especcially SScaling can cause many issues so i suspect that quite a bit.

So I made a wheel on my side, added a body box 250kg each wheel 50 kg. 4 constraints all locked just swing 2 free besides everything default value. Positions are equal (square) constraints again aligned, no center of mass changes etc everything default.

OnTick add torque. I have a switch to negate a vector since i rotated my wheels.Also thats why I get forward vector should be right vector normally.

No issues with even no additional torque

1

But just to be sure we can also accumulate torques which is 4x and negate on body

also lets be sure that we do not use bAccelChange =true since that would neglect mass entirely.

Also if you are using asyncs maybe do on async tick

As prototype with nice collisions, spline creation it works ofcourse gameplay wise would need much more but it works. What I would add to previous post, scaling and collisions really can be important on this setup so try manipulating meshes rather than scales and be sure you have smooth collisions and proper tires.

Placing the cart on its head, it works as intended.

(There is a debug sphere to better see the rotation direction of the wheel)

I decided to turn on parent dominates for both axle constraints, and the physics breaks as the front axle flies off.

Even odder how before nothing happened before when upright

I originally had the cart axles fixed in the same static mesh as the body (similar to your example), and it could successfully roll with “add impulse,” but the instability/wobbling was bad and led me to convert to an axle setup; plus, it is also more visually appealing as the axles run through the wheels.

Here is the collision of the wheel:

There are no Cylinder simple collisions, so I used Blender’s UCX prefix import to auto-convex the collision from an exact copy of the wheels.

CCD is turned on

Sphere and Capsule collisions don’t work as the wheel needs a cylinder that is tapered on the edge to turn on the tracks.

Please do share a better way to get a smooth, editable collision, if you know of a way, and suspect this to be a culprit.

Viewport of cart:

(The wheels are set in construction to automatically adjust width to track and

I am using twist on -90 z axis rotated constraint instead of swing - both seem to work same I have tested)

Seconds after start simulation

Numbers on screen:

Desired Smoothed Angular Velocity of Axles : Cart Max : Max Torque

I played with Angular Damping on the main body but it only slows the wheelie, doesn’t stop it.

Id like to use your torque setup but I would have to split the axles in half to apply the correct torque to the respective side. good to know about the node, though.

Im guessing debugging the Parent Dominates options may lead to a clearer picture of the problem?

Hi there,

Thanks for all screenshots and explanations, helps a lot.

First of all, your collisions seems ok, that should do the job. For smoother collisions, you can do envelope/shell in blender import collision to unreal. Even though because of the shape right now it can create an additional torque on body, after speeding it should generally stop. For testing if you want you can just add a simplified collision sphere or capsule but your collision is ok imo.

Parent dominates is ok, atleast we see something rather than stand still and wheels generally tend to move when placed upside down. Now this gave us a good specific that overall setup works, however there is some problem with mass, friction or similar. Let’s close Parent Dominates and CCD cause we don’t require them for now.

For constructor scripts, Let’s be sure that the wheels are first positioned correctly after that only simulation runs.

So I changed the setup like yours, made a cylinder, resize, bake its transforms.

Placed axles, inside I put the wheels. Closed wheels simulation since we don’t need simulation on them, we just need their collisions. Body 250 kg and each axle 200

Put constraints default and just open Swing 2 rotation

Scripts same

Even I go further one step and put cubes as wheels


In video I forget to put pin on accumulation vector but its ok without even with that it should work.

Couple of questions after these, did you try without the railroad tracks, maybe there is a problem with tracks? Is your sub mesh wheels simulated? they don’t require simulation. Also as additionally can you increase XY inertia tensor scales (2 or more) on the main body only (cart)

just to see it helps or something happens that we can diagnose further.

Ok - Progress!

Turned off Parent Dominates and Disabled CCD.

Turning off wheel simulation causes the cart to act erratically and then crashes the engine so I think I will leave it on for the time being, unless its a hard requirement.

Ive copied you blueprint for Torque:

(Quick question, why is this “Right vector” and not “Forward vector”)

I can get the cart to roll now! but, I can tell that the 3rd law is still a bit of a problem, as I can see that the Cart wants to flip forward (not backward like before with the Angular Motor?). If I pick the cart up during simulation it will do front flips.

This also makes keeping the cart on the track difficult.

Not sure if there is a solution to this third law flipping issue but - perhaps I can solve the “staying on track problem” by slowly ramping up the torque rather than all at once?

Does your cart do any flips if you pick it up mid simulation?

Also this project is in its very infancy so I dont mind sending you the project if you feel that would be better for debugging.

Again, thank you for the help!

Front flips from picking up during simulation:

Hi , its ok any change its a progress.

In short you can send the project from here or via github and I can take a look at it.

Yeah I rotated my wheels (I quickly did one without any attention) just rotated them after in blueprint. Thats why it was rotated. Now in the last on I dont really push torque to wheel, if you take a look we just put torque on axels so both frontL R wheel moves, since the wheels itself not simulated they are just child to axel.

You setup seems right. However you said Turning off wheel simulation causes the cart to act erratically and then crashes the engine that’s weird. Do you have anim bp on it, doing something on wheels? Cause in your setup you don’t actually need to simulate the wheels. Front Axel , Front Wheel L, Front Wheel R are just one block. Simulating FrontAxel would be enough if the wheels are just child of it so they will turn with axel, we don’t need to explicitly simulate wheels cause if you do they will be detached.

Interms of the still flipping issue or intense torque. Yes first lower the torque to a point where either you don’t see a movement or struggles to move. Secondly yes FinterpTo or timeline and gradually increasing forces is something very common practice. Third make Sure your body is havier atleast 2x than the total wheels&axels. So the dominant force of gravity around the body. If its not correct than simulation will assume body is neglectable gravity force pushing cart up in air.

I can only upload the .uproject here. Im guessing that wont help?

Github only lets me upload 100 files at a time and wnt accept the full folder hiearchy

I feel disabling the simulation on the wheel would help with the third law but the cart just takes off flying away during simulation even with no construction script or event functions applied.

I cant seem to figure out what is causing the issue. Must be a physics constraint but I dont understand why.

The wheels are separate static meshes that are held to the axle by Physics Constraints to the respective axle.

I did this so the Wheels Static Mesh and width from axle origin can be changed as needed

You don’t have to simulate and connect wheels with constraints.
You can just put wheels under axle without simulation. Simulate only axle and put constraint between axle and body.
Give a try.

You can zip project and send over wetransfer drive or similar file sharing.

Ah you are indeed correct. Let me make those changes and test it out.

If im still struggling ill send it over

1 Like

Have you figured it out, just checking on you.

Ok yes got it. Wheel definitely did not need to have its Physics simulated and thus, no physics constraints.

I suspect it was adding to the additional torque in the opposite direction but cant rule it out as it is still present.

The add torque node works much better then the angular motor. With a float curve I should be able to mimic ramp-up.

Still I can successfully get the cart to move with with 3000000 multiplied to the vector.

Question though: to clarify: it is the “RIGHT” vector because that is the vector the axles are parallel with correct? In other words, we are saying “rotate around [this axis]” when applying torque with the various vectors?

Results:

Now I just need to figure out if its necessary to prevent it from drifting in either direction… I would thing it would go straight but:

Ill do some more testing on the track.

Thank you for the help. I will mark the solution!

1 Like

“rotate around [this axis]”

So when you get a right / left / up vector, its a unit vector in world space where points to the direction. This is ofcourse mesh relative. In an optimum case, when your wheel positioned in the world to locationZero RotationZero, your wheel should point towards X axis.

Thus if you apply a torque in WheelForward x Strength it should start rolling. If you were doing kinematics and add rotation then you could have done WheelRight x Rotation.

My wheel was (as mesh) rotated badly so when positioned in the world to locationZero RotationZero it was already rotated, thats why I get the right vector and multiply by it since the right vector was looking forward (to the accurate direction).

If you have trouble understanding the forces and rotations which can happen, a technique I use is to visualise them by drawing debug lines. There is a node for that in the engine where you can set start and end points of the debug line and simply you can set start as wheel and torque vector as end to visualise the force vectors.

In terms of the drifting : Real physics vehicles drift usually comes from:

  • lateral tire friction
  • slip angle
  • surface friction
  • mass distribution

Thats a problem when your wheels are in contact in the world or not and depending on the state of contact, drift would happen. In order to prevent that I can suggest couple of things.

1- Always check your wheels in contact to ground via raycast apply torque that time.
2- Create a suspension, a linear limit on Z axis for the constraints. This is a simple way of making sure all wheels subject to have contact with the ground.
3- Even all wheels are in contact drifts are dependent on the surface and the cart itself. So In your car you can make a controller for steering to compansate the drifting. Your front wheels can have 1 2 degrees of steering / rotation limit and you can use this 2 degrees to compansate direction to the carts forward vector. That would decrease drifting.
4- You can increase your carts wheels gyro and increase the cart bodies Z tensor scale like 2 -4 to actually make it harder to turn and drift.

Also since you will be in a track that drift wont be an issue since it would be corrected anyway. There is an option for that when a penetration happens how much a force can be applied in the solver.

You can decrease this a bit to make the correction forces flicker the body if you have a very tight tracks for the cart.

Happy developing.