I am developing a true first person character and need to clamp the camera rotation. I want to prevent the head from rotating 360 degrees relative to the body.
I have an implementation that worked with the old camera system (second image), but I am struggling to replicate it in new gameplay camera system. How do I set these values in Blueprints? (first image)
Hi @Trudedro
Could you describe your problem in more detail? I don’t quite understand what you mean. Would you like to limit the X rotation of the camera in the blueprint?
Kind regards
your description is a little hard to follow: a human can turn their head relative to their body, they can typically go between [-80,80] if you want a different limiter then that is up to you on “realism vs video game”
there is a couple different ways you can accomplish this depending on how specific you want it to be, but you will probably end up with a combination of clamping the InputAction and clamping in the IA_Look.
your code is actually going to be very similar to the previous.
because you have already bound the InputAction AI_Look with the MappingContext In Blueprints your nearly there (C++ gets a few extra steps but I will continue with Blueprints only)
the bottom of the “Input Mapping Context” section of the doc showing how to register the MappingContext to the controller (if we are working inside the controller the node being called is different)
now actually limiting the Yaw (rotation about Z) :
the clamp inside of the MappingContext is referring to the output range for that component of the vector that will be handed to the ‘IA_Look Event’ as a result of the multiplier
because a controller joystick is a vector2<float> where either axis could be anywhere [-1,1] we often apply a multiplier to it to get more meaningful values
similar for a mouse which returns a delta of the motion on the XY plane we often don’t multiply that to allow for finer correction particularly at more precise games
so if you clamped the IA_Look to say [0,0] on the X that means that no matter how much the player moves the joystick or mouse in the X direction the IA_Look will always receive Zero for that component of the vector. you can still clamp it to prevent overshoot with doing the math in the IA_Look Event
on the blueprint graph for your character or controller right-click and search “IA” if you have been consistent with the naming (preceding your InputActions with “IA_”) then it will show all the InputActions that you have created, even those not a part of the current MappingContext.
the value included will be the vector2 after the multipliers have been applied. then you can split the pin (right click “split struct”) the Y value will be the up down, and the X value will be your Yaw rotation. After that you can just use the logic you had previous.
Sorry for the delay, I had some personal matters to attend to. I’ve uploaded a video to clarify the problem. The beginning shows the intended behavior where the animation catches up to the camera. At 0:10, when moving the mouse rapidly, the animation fails to keep pace, causing the camera to clip or show the character’s back
Okay, I’ve followed your suggestions. In the image, you can see how I implemented IA_Look inside my character blueprint (Pawn). The issue is that it still isn’t working:(
if you are going to be applying a hard limit to something, calculate the bounds then constrain the value within the bounds.
why are you doing YawMin = X+90-90 and YawMax = X+90+90?
you are adding 2 steps of floating point approximation variance, which in the case of both could introduce a winding issue, and the one for YawMin is absolutely unneeded.
then not doing anything with the intermediate value to justify the 2 steps of math.
maybe if you were attempting to get the visual Forward direction of the mesh to do something (because the logical forward is rotated by 90 degrees), but that in most cases would be the forward direction of the Pawn.
to check for winding issues output the YawMin, and YawMax values, and see if they are outside the bounds of [-360, 360]
if you need to do the math YawMin = X, YawMax = X+180 done.
even with this either way you might have a winding issue, and the camera only partially interpolates,
if we are not doing any math on the YawMin we don’t need to “unwind” it, but for your YawMax put it through: branch ( YawMax > 360 ) { YawMax -= 360; } and branch ( YawMax < 360 ) { YawMax += 360; }