0
\$\begingroup\$

I am trying to align a non physics vehicle to the same angle as the floor, using blueprints in UE4.27

At first, I used normals, but this has undesired effects when going over things like speed bumps.

I have tried LookAtRotation but that only gives pitch and yaw. I only want to get pitch and roll, yaw is controlled by the vehicle.

I have a location I get from a line trace at each corner. I want to compare this to a part on the vehicle (that is perhaps at floor level) to determine what pitch and roll I need to apply to the vehicle to align it to the floor or obstacle I am driving over.

\$\endgroup\$
1

1 Answer 1

1
\$\begingroup\$

Let's call the four points where your linecasts hit the ground frontLeft, frontRight, backLeft, and backRight.

This lets us find a vector with the amount of forward tilt (pitch) we want as:

forward = frontLeft + frontRight - backLeft - backRight

And the angle it makes with the horizontal plane is:

pitchRadians = asin(forward.z / length(forward))

Similarly for the side-to-side (roll) angle:

right = frontRight + backRight - frontLeft - backLeft
rollRadians = asin(right.z / length(right))

You may need to negate one or both and/or convert from radians to degrees, depending on the details of your coordinate system.

\$\endgroup\$
1
  • \$\begingroup\$ This code will underestimate the roll angle when the pitch is large (pitching tilts the axis you're rolling around, so the same amount of roll doesn't tilt your right vector as far on the z axis anymore). If that's a problem, you can compute a new up vector as normalize(cross(cross(forward, (0, 0, 1)), forward)), and then use the projection of right on this tilted vector instead of right.z. \$\endgroup\$
    – DMGregory
    Commented Aug 17, 2022 at 10:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .