Using body gyros with SetPrimaryPartCFrame()

One of the few ways to move entire models in roblox is using SetPrimaryPartCFrame(). In this case, I’m using a ViewModel and setting it’s PrimaryPartCFrame to the players camera on render stepped. I noticed a really nice effect can be created by using a body gyro in the model and setting it’s CFrame to the players camera CFrame. However, SetPrimaryPartCFrame overrides it.

I’ve tried setting just the ViewModel position to the camera and then using CFrame.Angles() with the ViewModels current Orientation. But, I keep getting an error that the 3rd argument is missing or nil. I don’t think Orientation is the right thing to use, but I’m stumped at what else I could do.

ViewModel:SetPrimaryPartCFrame(CFrame.new(Cam.CFrame.p) * CFrame.Angles(ViewModel.PrimaryPart.Orientation))

ViewModel.PrimaryPart.BodyGyro.CFrame = Cam.CFrame

What are you trying to achieve here?

I’ve already said, I’m trying to get the viewmodel to rotate using a BodyGyro without the BodyGyro’s rotation being overridden by the rotational component of SetPrimaryPartCFrame()

It might be something in the bodygyro’s properties.

Incorrect, The body gyro works perfectly on it’s own, I managed to test this using a body position and a body gyro, It’s just that body gyro updates every frame and primarypart cframe overrides this as it also has a rotational component. Max torque is math.huge. The reason I don’t just use the body position then is because I only want the ViewModel to tail the camera rotation, position should be set accurately, which is why I’m using SetPrimaryPartCFrame on renderstepped.

Have you tried to just remove the CFrame.Angles part of the first line completely?

Btw, for bodygyro to work (I am sure you know this, just saying incase) the entire model has to be unanchored

If you don’t include a rotation in SetPrimaryPartCFrame It then substitutes it to CFrame.Angles(0,0,0) It still overrides bodymover as you are setting a CFrame that has both position and rotational components. Yes, the entire model is unanchored.

I mean, this might be desperate, but have you tried to just use ViewModel:MoveTo()?
as this function only changes position it might help.

Umh, I think you’re confused on what a ViewModel is. ViewModels are basically the arms that are glued to your camera in a fps game. You can only use MoveTo() on a Humanoid entity.

No, you can use MoveTo on models, it’s quite useful. It’s just for changing the position of models. I often use this when I teleport players.

Wasnt aware of that, anyway MoveTo() would make the models position trail behind the actual player aswell, so It won’t be usefull. I’m sorry for any confusion. It’s my bad for not including visual evidence: https://gyazo.com/7896e66a2e6af33dd9c7ee64cd4c8933

For context, I’m trying to make this arm trail behind the camera rotation instead of moving to it instantly on frame like it’s position. However, to set the position I need to use SetPrimaryPartCFrame that also overrides any other rotation I try to add to create the trail effect.

Very weird indeed. I hope someone else can help you. I would love to look into it further, but it’s super late right now and I should go to bed. Good luck buddy!

1 Like
NewCF = Part.CFrame + (Camera.CFrame.p - Part.Position)

Keeps the part in the same rotation, only translating to the same position as the camera

3 Likes