Add torque to static mesh component in direction camera is facing. C++

While relatively simple logic I’ve spent the last two days trying to figure it out and can’t for the life of me. I’m working with a custom adaption of the rolling template basing some of my code on that provided. One of the differences in control that I’m trying to implement is having torque added to the mesh in the direction that the camera is pointing, rather than simply along the X, Y axes. The pawn I’ve created has the same hierarchy as the one in the template (StaticMeshComponent → SpringArmComponent → CameraComponent) and I have all controls handled through a PlayerController as opposed to the the Pawn itself as is done in the template. Everything but my MoveForward() and MoveRight() functions work as expected. The two where torque should be applied to the StaticMeshComponent. What I can’t figure is how to use the Camera’s forward vector to apply torque to the StaticMeshComponent in the corresponding directions: MoveForward() - forwards and backwards relative to the Camera’s forward vector, MoveRight() left and right perpendicular to the Camera’s forward vector.

Here are the .h and .cpp file for this pawn. The code in MoveForward() (other than the if-statements) are my lackluster attempts at getting it to work, the block of commented code is split into different iterations with the use of multiple comment blocks/lines.

Any help figuring this out would be greatly appreciated.

If you want the torque to move you forward then you should use the “right vector” as the input axis – like a wheel axle. Forward/backward will be positive/negative values or vice versa – not sure which.

So the torque vector should just be GetRightVector() from the camera (tho if you’re doing the camera right then I’d use GetControlRotation() and get a forward vector from that). Then multiply that vector by the axis value and apply the torque.

And for right movement, use the forward vector (again, left/right will depend on the sign, not sure which but i bet right is negative).

I think that’s what you’re asking and what the docs say.

“Like a wheel axle.” Exactly what I was looking for, thank you. As you can probably see in the files I had the GetRightVector() and GetForwardVector() in the opposite functions to where they should have been. Works perfectly now.