Top down shooter C++ movement rotation.

I’m trying to implement a top down shooter based on the likes of the old midway games where the player can only move along the x and y axis, but when moving left and right their ship will roll slightly to the left and the right respectively giving the illusion of flight.

Now whilst there are tutorials on how to do this in blue prints I’ve not been able to find anything with C++. I’ve followed the documents standard input tutorial for the x and y axis to get my pawn moving but I can’t quite figure out the rotation.

Could anyone give me a hand with this?

As a clear example:

Player presses D: Ship moves right, rolls slighly to the right.
Player lets go of D: Ship remains still, ship rolls back to original position (level or straight).

Player presses A: Ship moves left, rolls slightly to the left.
Player lets go of A: Ship remains still, ship rolls back to original position (level or straight).

Thanks!

Euden

I feel like you could use something similar to the set-up I’m using for a hovercar that aligns itself to the terrain - I get a vector orthogonal to the ground and then apply torque to reach that rotation. If you want some slight roll, you could calculate a rotated normal vector, then apply torque every tick like so:


		FVector torque = FVector::CrossProduct(normal, ShipMesh->GetUpVector() * -1.0f) * TorqueStrength;
		ShipMesh->AddTorque(torque);

Then, when the player releases the input, reset your normal vector to one going straight up.

Hope this helps!