Parking Using a MoveTo Behavior For Vehicles In Unreal Engine 4

Parking in a specified direction involves two steps: the approach and the landing.

Parking, the Approach

We could just fling our vehicle directly at a destination and let it line itself up when it gets there. However since there are 360 angles it could arrive at and 360 angles it could be destined for, it may spend quite some time turning around. So ideally we want it as close as possible to its final rotation when it begins the landing.

To do that, we're going to inject a waypoint into the array of Path Points returned by the NavigationPath object. We want to calculate a waypoint that is 90 to 180 degrees behind the destination. If the vehicle is in front of the destination, it'll aim for 90 degrees to the side. As the vehicle drives behind the destination, it will curve inward to 180 degrees directly behind the destination:

The similarity to aircraft landing is not lost on me.

The distance behind the destination (the yellow dotted line above) is determined by:

The result is a rotator from 90 to 180 degrees, to be added to the final rotation. The numbers work out like this:

Angle

Rotator

Length

-180

90.1

1

-150

115.8

0.96

-120

137.9

0.86

-90

155.9

0.70

-60

169.1

0.5

-30

177.2

0.25

0

0

0

30

-177.2

0.25

60

-169.1

0.5

90

-155.9

0.70

120

-137.9

0.86

150

-115.8

0.96

180

-90.1

1

Here's the blueprint:

Parking, the Landing

Once the vehicle is likely behind the destination, probably facing nearly the correct direction, and within CloseEnough(), we can start actually parking.

The primary goal is to align the vehicle along the rotation plane that passes through the destination. That's the hard part. Then it's a simple matter to forward or reverse to the destination.

We need to calculate a target to steer toward again, but unlike the Approach target, the Landing target will always be in a line along the rotation plane. The farther to the side the vehicle is, the straighter it will aim directly for the plane. As it gets closer, it will steer to drive alongside it:

I would have been more interested in trigonometry if the problems were like this instead of the height of trees.

We need three values: how far the vehicle is along the plane, its distance away from the plane and whether the vehicle is facing toward or away from it.

We know how far the vehicle is along the plane (the yellow line above) using: