Hello everyone! My objective is to produce a flat, thin box to represent a road in Unreal 5.1 and set it up as a Pawn so that:
- It has a constant velocity in the direction of its local forward vector.
- When the player presses A/D, it makes a smooth curve up to 60 degrees left/right .
- When the player presses W/S, it makes a smooth curve up to 20 degrees up/down.
- It has collision so that another Pawn can move along on top of it.
I have a naive approach I’m using currently that goes like so. For set up and construction script:
- Create a child (call it Road) of the default third person blueprint.
- In Road, replace the default static mesh with a cube (call it Leader and make it invisible).
- Attach an instanced static mesh component to the Leader (call it Segment). For context, Segment is basically a slice of the overall road shape I want when it’s traveling there’s no rotation input being applied.
- According to a variable called Count, add Segment instances to the Road at an increasing offset from the Leader.
On player input:
- For A/D inputs, add one degree scaled by the input value to the yaw component of the Leader’s rotation. The output is clamped to (-60, 60).
- For W/S inputs, add one degree scaled by the input value to the pitch component of the Leader’s rotation. The output is clamped to (-20, 20).
On event tick:
- Move the Leader in the direction given by the local forward vector.
- Give the first Segment (index 0) the same location and rotation as the Leader.
- Interpolate every other Segment’s rotation and location towards the rotation and location of the one in front of it.
While this does give the overall result I want, there are some issues with this approach that make me want to move away from it:
- I have no idea how to texture the Road so that it has a consistent look, and it seems like it would be excessively difficult to do so.
- Making it move properly is very finicky because I have to set the rotation speed globally and locally as well as the forward velocity to very specific values to get smooth curves, especially left and right.
- When moving vertically and horizontally at the same time, the curve is not smooth and there is a tendency for “lumps” to form on the sides of the road.
I tried to address (3) by adding roll to the road’s rotation when it’s moving horizontally and vertically at the same time, but that didn’t really have much of a positive effect.
Do any other more experienced developers have suggestions for alternative ways that I could approach this, or else modify my existing design?