So, I’m making a roller platformer in UE4, and I have keyboard and joystick input to move the sphere, but I also want to include the mouse and right analog sticks to control the camera looking at the ball. I’ve configured everything for the camera rotate around the ball (which is a Pawn) without being affected by the ball’s roll, yaw and pitch rotation’s values, but even if I rotate the camera, the ball always has the same direction when moving, meaning that if I press forward, and rotate the camera, the ball always has the same direction.
How can I manage to make the camera change its direction according to where the camera is looking? I think this is the same principle as Orient Rotation to Movement regarding Characters, but as I’m dealing with a Pawn, I can’t manage to find anything like that.
Get the forward vector of the camera, and the forward vector of the ball.
Lerp between these values, using a scalar value in the Alpha parameter to get a “Target Vector”.
Finally, multiply this target vector by the speed at which the ball is currently travelling (or slightly less, for a more realistic feel).
This will smoothly create a new position between where the ball is currently rolling toward, to where the camera is telling the ball it should be rolling toward.
Alternatively, you can try using Rotation vectors instead, and just change the ball’s Yaw to match the camera’s (perhaps also with linear interpolation to smooth it out)…
If the issue is that you are manually rotating the ball as it moves, perhaps you should consider making the ball a child component to a default scene node. Then, instead of rotating the entire pawn, only rotate the ball mesh, keeping its parent in the same upwards orientation as the camera.
Hey, everyone! So, after some research, I’ve accidentally found the solution in my problem in a topic about the Camera Spline functionality. So, basically, you have to make a rotate vector (RotateVector) based upon the vector generated from the product of the axis value and the defined speed, and a rotator created from the Yaw/Z of the CameraRotation of the PlayerCameraManager. After that, add that to an AddForce or AddTorque node, and the Pawn will go where the camera is rotating.