How can I clamp the rotation of the character on a moving object?

Hey guys I want clamp yaw axis by 90/-90 degress when the player enters the vehicle but using the regular method clamp is looking at world space rotation instead the relative rotation of the character to the car. How would I go about changing it?

Here is the problem in action :

Hey @SolidLoL ! Welcome to the forums!

How are you getting into the car? If you’re using “Attach Actor to Actor”, you can use the dropdowns there, try the rotation one and definitely don’t use “Keep World”.

It looks like you’re not clamping at all, really. Maybe on the car try using “Get Player Pawn”, get “Camera”, and get the Z rotation, clamp it to the car’s rotation Z -90 for min and car’s rotation Z +90 for max. Then set the rotation using “Set Actor Rotation.” Make sure to pass in the original X and Y to the Set Actor Rotation!

And have all of this on tick- but make sure it’s not activated until you get INTO the car! :slight_smile:

Hope that helps! Come back with your code if you need more help! :slight_smile:

Hello!

Thanks for the quick response, I am using the Horror Engine template which has a lot of dependencies, plus the Look function is on a separate blueprint from the character controls.
To get into the car I use the “Attach Actor to Component”, with the rotation rule as keep relative.

My goal is, that when the player enters the vehicle the default movement keys will control the car while the camera controls and other functionalities are using the character controls.


I got this working by moving the vehicle controls to the character blueprint and adding the mapping context when the player enters the car. (probably not the best idea)

If you don’t mind can you give me a little bit more detail how to clamp the cars rotation Z to the cameras and set the actors rotation?
I am a little bit confused because I thought since I attached the player to a component of the vehicle, the relative rotation to the parent should not change if the parent is moving so it should be easy to restrict from there)

Unfortunately, this is highly unorthodox. I’m… very curious why that’s a thing. But because of that it means that we need to know everything about the third blueprint that has the camera controls because we’re going to have to pass it through multiple blueprints to get the clamping signal to reach it. It may not be staying relative because the camera itself isn’t relative to the facing of the player, it could be something else, it could be a lot of things with this statement :frowning:

So a little bit of an update since last time. With the help of chatgpt I was able to clamp the players camera with the following codes: One on the vehicle the other on the player

However, if the player`s rotation goes below -180 or above 180 by rotating the camera fast or turning the vehicle, the camera snaps towards the centre by 90 degrees.

I solved the problem by using a delta rotator between the player controller rotation and the cars rotation. The blueprint below also rotates the player towards the car`s rotations after a few seconds of the player is not looking and the car is above a certain speed.