Can I rotate Actor while grabbing?

Hi everybody …
Sometimes, when the pawn grab the Table or other object, i tried to add code to rotate that, but every time the rotation return to the origin.

1- I added new Input Key ( Z Input Key to rotate Z-Axis )
2- The code is:

float ZAngle=1.0f;
void Grabber::RotateZAxis(){
FRotator Rotation;
Rotation.Pitch = ZAngle++;
PhysicalHandle->GetGrabbedComponent()->GetOwner()->SetActorRotation(Rotation);
}

Are you creating ZAngle as a global variable (outside of the class declaration)? That is generally not a good idea, globals are bad form unless absolutely necessary.

Your code is creating a undefined Rotation which probably defaults to (0,0,0), then changing the pitch to 1.0, so it will rotate your object to that. Keep in mind the things you pick up may not be at 1.0 pitch, and your code will ignore whatever angle they were at before you pick them up. Also, the ZAngle will not advance until after it sets the Rotation.Pitch, so the first call will set it to 1.0, then increment to 2.0. The next call will set the angle to 2.0 and the increment to 3.0, and so on. Not matter what though, it will rotate to 0.0 Roll and 0.0 Yaw.

You would be better off adding a new member variable to the Grabber class to hold the object rotation, it can be private. Set it when you pick up something to equal the object’s initial rotation, then increment the pitch with your RotateZAxis input function.

Hi,

Due to inactivity the thread will now close in 7 days.
Please either contact a moderator for it to be unlocked or start a new thread.

Thank-you

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

Privacy & Terms