Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you rotate a model or make the model face an object?

I have a NPC model that you can move around by clicking.

I also have it set to where when you click a tree it goes over to it.

When the NPC goes over to the tree it is not facing the tree.

I need help figuring out how to get a model to rotate or face towards something.

1 answer

✓ Accepted answer

This can be done with some basic knowledge of Model and Vector3/CFrame. Note: I will only give you an idea, not a script.

Model

So a Model has a property of name PrimaryPart which means that the other parts inside of a model will maintain their orientation and offset perspective to the PrimaryPart if it moves, so basically, they will follow and rotate according to their perspective of the PrimaryPart if it's moved/rotated. Note: The part that you assign as PrimaryPart has to be a descendant of the Model itself!

PrimaryPart

Model.PrimaryPart = Model.part --specify your primarypart

Vector3/CFrame

You want the model to face the tree and make it not point vertically. We do this by keeping the PrimaryPart's X/Z position the way it was before but change the Y axis according to the tree position.y.

easily done like this:

lookTo = Vector3.new(Model.Part.Position.X, tree.Position.Y, Model.Part.Position.Z) --we store it as a variable so we can use it on the CFrame late on

Then we use the lookTo variable onto the PrimaryPart's CFrame to change its rotation, according to the tree.

Model.Part.CFrame = CFrame.new(Model.Part.Position, lookTo)

CFrame, Vector3

2 comments

0

This almost works for me, when they try to rotate they trip and fall then when they stand up they are facing away from the tree.

0

Fixed

This discussion is preserved as it was. New answers, comments, and votes are closed.