Rotation snaps every 90 degrees

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

float param = GetInputAxisValue(LookRightBinding);
float param2 = GetInputAxisValue(LookUpBinding); 
     
GunRSideMeshComponent->RelativeRotation.Yaw = atan2(param, param2)* 57.2957795;

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:

There a define value for it, so try with atan2(param, param2) * RadiusToDegree

HI,

you should check param and param2 values, GetInputAxisValue may always return -1.f, 0.f or 1.f instead of analogic value in range [-1.f 1.f].

Hope it helps.

I tried RadiansToDegrees but it needed a variable so I did:

float param = FMath::RadiansToDegrees(GetInputAxisValue(LookRightBinding));
float param2 = FMath::RadiansToDegrees(GetInputAxisValue(LookUpBinding));

but it the rotation barely moved like it was still radians :frowning:

What function would use analogic value ?

Hi,

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.

Oh sorry. yeah, it returns -1 , 1 and 0 when doing nothing. What retrieves degrees/radians then?

The snap isn’t drastic as it still rotates 360 degrees , but it’s noticeable .

I tried

   const float FireForwardValue = GetInputAxisValue(FireForwardBinding);
	const float FireRightValue = GetInputAxisValue(FireRightBinding);

 const FVector LookDirection = FVector(FireForwardValue, FireRightValue, 0.0f);
    const FRotator LookRotation = LookDirection.Rotation();
    float rot = LookRotation.Yaw;
    
    WheelArmBackComponent->RelativeRotation.Yaw = rot;

and this is the exact way the samples rotate and it feels exactly the same as doing it the first way(they also use the get function).

I don’t know how else to do it…

Well, thanks for your help anyways ^ ^

I tried atan2(param, param2) * RadiusToDegree

as Fmath::RadiusToDegree(param); ect but it didn’t do anything :frowning:

Usually we’re accumulating deltas from the gamepad inputs with something like:

const float FireForwardValue = GetInputAxisValue(FireForwardBinding);
const float FireRightValue = GetInputAxisValue(FireRightBinding);

const FVector LookDirection = FVector(FireForwardValue, FireRightValue, 0.0f);
const FRotator LookRotation = LookDirection.Rotation();
float DeltaYaw = LookRotation.Yaw * GetWorld()->GetDeltaSeconds() * RotateSpeed;

WheelArmBackComponent->RelativeRotation.Yaw += DeltaYaw;

I tried that and it’s smooth, but not the effect I was looking for. With that, the object keeps rotating simply by pressing one way.

I’m needing to have it move where ever the stick is pointing for a gun

this is a prototype I made (temp art) for the game I’m making and this is how the character moves.

I dunno, the prototype one rotated butter smooth(just used C++/DirectX), but UE 4 rotation feels off

seriously though, thanks for helping :slight_smile:

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 :

This is the way that it should be:

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.

changing the Deadzone fixed it