I’ve got a twin stick shooter character and a level filled with static cameras placed in the world. I can’t figure out how to set my characters rotation (where he is aiming basically) to be relative to the camera’s rotation instead of the controller rotation. In the image I show my current setup, which works fine using an attached camera or a camera with the same starting rotation. So how can I set up the rotation to take into account the camera actors location?
Create a new project using the third person character template. This example has the blueprints and character movement settings that let you move where the thumbstick points, regardless of the camera angle.
Movement isn’t the issue, rotation is. Movement is fine. Okay but how can I translate the third person templates rotation setup to a top down perspective using a camera not connected to the character on a stick but instead static in the world?
wait. I dont understand yet. So what kind of movement are we talking about here? I thought you wanted it to go directly in the direction the thumbstick is moved without having the player turn to face that direction first. That’s not what you meant?
No, movement is fine, movement is working as expected, rotation is not. The character moves in the direction of the keypad/thumbstick relative to the current static camera. Rotation, i.e looking in the direction of the other thumbstick/mouse is not currently relative to camera. I’ve got the movement done, I need the rotation- where the character is looking/aiming not where the character is moving.
The image I posted shows my current setup for rotation, which works fine but isn’t relative to the current camera view, meaning that if my character swaps camera view to one thats say, rotated 180 degrees, then all the pawn rotation is backwards and gets very messed up. My level is made up of different sections each with their own static camera thats not connected to the character- I need my rotation to respect the changing camera view. So aiming north, East, South or west is always decided from the perspective of the current camera. Does that make more sense?
Yes it is clearer now. What have you tried so far which involves the camera’s forward vector?
I suck at math, so not much. I use the cameras forward and right vectors to help with movement but have no idea how to add them into my rotation.
Sorry I’m not great at rotation vectors either, so I’m not sure how to approach this problem myself.
But I have an idea that maybe your current code in the screenshot is assuming the camera is lined up with the player, so maybe all we have to do is get the camera’s Forward Vector and then GetRotationFromXVector from that, and add the result to the GetRotationFromXVector you already have, and feed THAT into the Target of the RInterpTo.
Sorry I don’t know if this will work but that’s what I would try next in your situation.
I get what you mean, I’ve been thinking the same thing myself, I just don’t know how to implement that. I don’t know if im adding, multiplying or subtracting vectors or where I should adding these nodes. I’m totally fine with starting the rotation again from scratch but again, don’t know how to implement what I need.
Have you tried “Get Hit Result Under Cursor” node by any chance?
Not because I don’t understand what that node would do when the player is using a thumbstick or keyboard as opposed to a mouse cursor.(I assume by cursor that what it means) I wanted something that works with any control scheme.
A’ight, then you can spawn a “Crosshair” Actor on the floor and move it along the plane according to your device input. And then get the Character to look at it at every tick.
So you suggest I create a Crosshair actor, and use that to set the characters rotation? In theory that sounds great but I am not great at programming yet and that sounds like it would be harder to implement that finding a way to align my inputs with the cameras forward vector. Would that not just lead to the same issue but in the crosshair actor instead, as that would need to rotate/move based on the input from the camera actors perspective?
Pardon me if I’ve misunderstood you by any chance, but can’t you repeat “The character moves in the direction of the keypad/thumbstick relative to the current static camera” for the crosshair too with identical logic mapped to the other “thumbstick” (or whatever you want)? Then it’s just a matter of getting the character to face the crosshair, right?
This is my simple movement set up right now. I’m not sure how that would translate into a cross hair actor. I don’t really want a cross hair to be able to be anywhere on the screen but assuming it was an invisible actor wouldn’t it cause issues still? Like wouldn’t that make the ‘speed’ of the rotation depend on how close the cross hair actor is too? Like if the cross hair actor was far away the player would rotate slowly and if it’s close the actor would rotate super fast etc rather then at a constant speed? Also what if the player didn’t rotate at all for a while and ran in a straight line for a few minutes leaving the crosshair actor way behind, then rotation would be painfully slow? I appreciate your trying to help but I don’t think I understand what your suggesting :S
Oh, alright so that’s the kinda control you’re lookin’ at. Did you try adding the Current Cam’s Yaw to the Yaw of your XY-derived rotation before setting it as the Control Rotation? (Try Yaw or Roll, I think one of them should work out)
This is my new setup, and for now this seems to be working for me personally without issue. Hopefully this is a correct method and maybe this will help someone else out with a similar issue. Thank you everyone for your replies and help.
Oh nice. I didn’t know about the Rotatevector node