Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
mnaj22 44
8 years ago

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

Log in to vote
1
Answered by
Kryddan 261 Moderation Voter
8 years ago

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 PrimaryPartif 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

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. mnaj22 44 — 8y
0
Fixed mnaj22 44 — 8y
Ad

Answer this question