enter code here enter code here`there’s probably a better way to do this, but I’m simply rotating a mesh on the yaw rotation and it snaps in place every 90 degrees. I’m currently using
I just rotated like I did in my own engine when I only used radians so I didn’t have to convert to degrees and it didn’t do this snapping every 90 degrees. Am I not doing the calculation correctly?
EDIT:
this is a video showing my problem. I’m rotating it smoothly around on the analog , but it snaps every 90 degrees 0/90/180/270/360 :
This is in my old engine I made myself, rotating smoothly without any snapping:
i think you misunderstood, GetInputAxisValue returns a number between -1.f and 1.f that represent the gamepad stick position (left/right and up/down), as it is not an angle it makes no sens converting it to Radian.
I asked you to double check the values in param and param2 (by printing it or breaking in code and watching them) to be sure these values are valid.
Looking at the vid there are 2 posibilities you want:
Option 1. Rotate the yaw based on 1 input axis. Notice that obtaining 2 input axis’ values to adjust 1 angle (Yaw) makes no sense. If you use 2 input values to adjust 1 angle, you’ll get shaking effects.
The solution for this is as follows, make sure you make an axis binding to a function that gets called.
For example: InputComponent->BindAxis(“Mouse X”, this, &YourClassName::OnMouseXChange);
Then in the function OnMouseXChange(float val)
const float speed = 10; WheelArmBackComponent->RelativeRotation.Yaw
+= val * speed;
Option 2: Make the gun point in the direction of the mouse position on screen.
The direction vector depends on the mouse position to the axis of rotation of the gun: FVector shootDir = mousePos - gunRotationOrigin. (Make sure they are both in screenSpace or in worldSpace)
From then, you can just obtain the rotation with: WheelArmBackComponent->RelativeRotation
= shootDir.Rotation();
Thanks for the input! But I’m using an analog stick, not the mouse(but I will be as a second control option)
The video show my old one . The shakiness in the vid is done on purpose as it’s a machine gun
this is a video showing my problem. I’m rotating it smoothly around on the analog , but it snaps every 90 degrees 0/90/180/270/360 :
The mouse was just an example. Both mouse and gamepad provide a value in range of [-1 +1]. So it makes no difference.
The only thing you have to do is read the Axis value out and add it to the RelativeRotation.Yaw with some speed multiplier.
eg.
WheelArmBackComponent->RelativeRotation.Yaw += AxisValue * Speed;
Btw, in the ‘correct’ example its also wrong. If the character is aiming down it flips 180 degrees.