Rotate an actor with physics enabled

I’m trying to rotate an actor based on the mouse position. Physics are enabled on the actor with X, Y and Z Rotation locked in the physics category.

The problem is that I can’t rotate it whether it is via code of using the rotation tool in the editor. Removing the rotation and using the editor tool to rotate the actor does not work.

Completely disabling physics works however, I want physics on the actor.

With the rotation lock and physics enabled, I can rotate it only by directly modifying the transform rotation value. However, this works only in the editor not in code.

In code when I rotate the actor the rotation does not change instead, for some reason, the location changes. It seems that physics it the problem, but I need physics enabled.

Here’s a code snippet

// function called when the player moves the mouse.
void AMoonPlayer::RotateActor(float value)
{
//sMesh(Static Mesh) = UStaticMeshComponent
//I attempted to unlock the Y rot to try to fix the issue(it didn't work)
	sMesh->BodyInstance.bLockYRotation = false;
//act(Actor) = USceneComponent
	act->AddRelativeRotation(FRotator(0, value * sensitivity, 0), false, (FHitResult*)nullptr, ETeleportType::TeleportPhysics);
	sMesh->BodyInstance.bLockYRotation = true;
}

Some more context could help. What is act? Is it a UChildActorComponent or a usceneComponent?
Show at least the constructor

I added comments to better understand my code.

What would be the use of the constructor ? I don’t have any code in it, sMesh and act are referenced directly in the editor

What is the relation between act and sMesh?
Are any of them the root component?
Which is parent & which is child?

act and *sMesh are the same component just a different type. It is a root component. Forgot to mention it, I set sMesh as the RootComponent and set simluate physics to true in the constructor other than that, the constructor is empty

You are only rotating act in you function. Your skeletal mesh will not rotate.

I added an arrowComponent to it and SetHiddenInGame(false) and the component rotates.
If you want to rotate the mesh then either attach it to the act scene component or rotate the SkeletalMeshComponent

1 Like

That worked thanks