Make NPC look at while walking

How would you make an NPC look at a part while they are walking? Using CFrame with a while loop makes it so the NPC is teleported to their own position every loop and unable to walk forward.

4 Likes

i think you could try messing with orientation instead of cframes since cframes affect position and orientaiton (if im not wrong)

3 Likes

Can you show me an example of this? If im not mistaken I don’t think you can directly write to the orientation no?

1 Like

Here is a link: How to change orientation

2 Likes

Try using bodygyro, Insert it inside HumanoidRootPart and make it look at the part while walking.
Remember to constantly change bodygyro’s cframe with script.

3 Likes

When you say look at a part, do you mean that their head should be rotated to look at the part, or do you mean their whole body faces the part?

3 Likes

The humanoidrootpart. So yes the whole body

1 Like

You can use a BodyGyro (though they’re deprecated now, I think) or an AlignOrientation object. Check out the wiki articles for those, they’ll probably do a better job explaining their usage than myself

1 Like

you could try using CFrame.LookAt to force the npc to look at the object while moving, you would have to recframe them every frame, though.

I thought about this but wouldn’t it be performance heavy?

…No? Where are you getting that from?

Running code every frame can be performance heavy, but for something a simple as a single calculation that changes the angle of the character, it won’t damage your performance.

Now if you have say 100 characters doing this same thing, then you might notice it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.