I’ve been at this problem for a week now, I’m still new to 3D development but I have a good grasp on Vectors and the Rotation class.
I’m currently trying to allow the user to pick up and object, move it into the view of the camera, and have them drag their mouse around to inspect the object.
I have two components on the custom Actor, a Scene component that is the root, and a Static Mesh which is the actual object. When applying Pitch rotation to the Actor, I apply it to the Scene, and when applying Yaw I apply it to the mesh. this way the mesh can be rotated left to right, and the whole Actor can be rotated up and down without being dependent on the Mesh’s rotation.
void AMPlayer::AddControllerYawInput(float value)
{
if (holding != NULL && LeftMouseDown)
{
holding->StaticMeshComponent->SetWorldRotation(holding->StaticMeshComponent->GetComponentRotation().Add(0, -value * 5, 0));
return;
}
if (cameraLock)
{
return;
}
Super::AddControllerYawInput(value);
}
void AMPlayer::AddControllerPitchInput(float value)
{
if (holding != NULL && LeftMouseDown)
{
float nextVal = holding->RootSceneComponent->GetComponentRotation().Pitch + value * -3;
// Ry and prevent crazy rotation issues by limit the pitch amount
if (nextVal >= 85 || nextVal <= -60)
{
return;
}
holding->RootSceneComponent->SetWorldRotation(holding->RootSceneComponent->GetComponentRotation().Add(value * -3, 0, 0));
return;
}
if (cameraLock)
{
return;
}
Super::AddControllerPitchInput(value);
}
The above code checks for mouse input using bools I set, and checks if the Player is currently holding an Actor. I get strange rotation results like this:
Any time I move the mouse over and over, the object has “locked” and won’t continue to rotate. I just want simple mouse rotation on this Mesh, but I’m not sure of the best way to execute it.
In UE4, is there a function similar to the Transform.rotation function like in Unity?
Any help is appreciated!