Lock Player position

Hey there,
So I have my character that picks up weapons when looking at it by attaching it to a socket and snapping it to the socket. What happens is that if the weapon is below the player, it pushes the character up. What I am hoping to do, is lock the player in place but only in the Y(Z) direction. I am not exactly sure how to go about doing this. Maybe limiting the players Z Velocity?

This is how i snap the target:

void APlayerCharacter::Use(AUsableItem* curItem, FName Socket){
	curItem->getItemMesh()->AttachTo(GetMesh(), Socket, EAttachLocation::SnapToTarget, true);


Any help is appreciated, thanks

In the physics constraints for the actor, you can prevent movement on a per axis basis.

the alternative is just setting the player Z axis position every frame.

I’m sure there are more elegant solutions that i’m not aware of however.

How do I reference the physics constraint in C++? I am new to Unreal.

You can try this:



Or this:

GetRenderComponent()->BodyInstance.bLockYTranslation = true; // Lock Y Location
GetRenderComponent()->BodyInstance.bLockXRotation = true;    // Lock X Rotation
GetRenderComponent()->BodyInstance.bLockZRotation = true;	 // Lock Z Rotation