What are some cool things to do with :SetPrimaryPartCFrame?

I just found about this thing and it’s really cool. Basically, it moves the primary part which is essentially the main of the car/model. It also keeps other things that are on the car to move with it too. So, i’m wondering on what to try do with this cool thing.

2 Likes

There is a lot of issues with using PrimaryPartCFrame, If your looking for an easier way to move a model use :MoveTo or if you don’t have to many parts you can also try tweens.

local Model = --Your model
Model:MoveTo("The position you want it to move to")

Though PrimaryPartCFrame does have it’s advantages being able to move the model by cframes for example using LookVectors.

There probably aren’t as many use cases for using Model:MoveTo() as there are for using Model:SetPrimaryPartCFrame(). Moving a Model using MoveTo would be like the equivalent of moving a Part by changing its Position property, and the disadvantage of that is you would have no control over the model’s orientation, and it would be offset upwards if there are any intersections with other parts.

I often use SetPrimaryPartCFrame for animating models like machines with moving parts, flying vehicles, tweening doors and windows, or other moving things for which I might choose not to rely on Roblox’s physics engine.

1 Like

In a strategy game I worked on a while ago, players can place buildings by clicking somewhere. The building automatically sits “upright” compared to the ground it’s placed on:

image

The buildings can also be rotated. This is done using SetPrimaryPartCFrame.

In a spaceship building game I’m “working on”, ship modules can be snapped together with magnets:

image

In code, this works by setting the PrimaryPart of a ship module to a Part at the center of a given magnet, and then calling SetPrimaryPartCFrame on the ship module and setting it to the CFrame of the opposing magnet, rotated 180 degrees.

1 Like