Model orientation facing wrong way?

So i’ve been trying to rotate a model making it face other object. But its facing the wrong angle.

while task.wait() do
	local torso = findtarget()
	if torso then
		unit:PivotTo(unit:GetPivot() * CFrame.Angles(0,math.rad(torso.Orientation.Y),0))
    end
end
2 Likes

Turns out that if there are object in their left/right side it will just rotate 360 degree slowly.

1 Like

Maybe you can replace CFrame.Angles you are currently using with something like (keeping everything else the same):

CFrame.lookAt(unit.PrimaryPart.Position, torso.Position, unit.PrimaryPart.CFrame.UpVector).Rotation

Where you would replace unit.PrimaryPart with whatever current part you are basing this off on from within the model.

Note that this code assumes you only want to rotate on the Y axis and not the X and Z axes. If you want to rotate the X and Z axes, replace with:

CFrame.lookAt(unit.PrimaryPart.Position, torso.Position, torso.CFrame.UpVector).Rotation

1 Like

Still not working. It instead change the unit position far far away

CFrame.lookAt(unit.HumanoidRootPart.Position, torso.Position)

I tried this and it works perfectly fine. But the only issue is if the object are getting closer it change the X axes

1 Like

How about this:

while task.wait() do
	local torso = findtarget()
	if torso then
		unit:PivotTo(unit:GetPivot() * CFrame.lookAt(unit.HumanoidRootPart.Position, torso.Position, unit.HumanoidRootPart.CFrame.UpVector).Rotation)
    end
end
1 Like

still nope, it faces the wrong direction too

1 Like

Oops try getting rid of the unit:GetPivot() that’s probably interfering. Also get rid of the .Rotation property

1 Like

do i replace GetPivot with unit.PrimaryPart.CFrame?

1 Like

No just delete it as well as the .Rotation property you should be left with:

PivotTo(CFrame.lookAt(unit.HumanoidRootPart.Position, torso.Position, unit.HumanoidRootPart.CFrame.UpVector))

This way, you are simply changing the CFrame of all the parts to face this same way

1 Like

It works but if an object is higher than it it would also rotate the X axes

1 Like

Ohhh I missed one important thing. Change it to:

local lookPoint = Vector3.new(torso.Position.X, unit.HumanoidRootPart.Position.Y, torso.Position.Z)

unit:PivotTo(CFrame.lookAt(unit.HumanoidRootPart.Position, lookPoint, unit.HumanoidRootPart.CFrame.UpVector))

This way, it never looks up or down; the Y component of the position of where it is facing will be inline always with the object

2 Likes

oh it works. Tysm lol i have been struggling this for roughly 1 hour

1 Like

Glad I could help! Sorry for the back and forth on my end; it’s been a while since I’ve used pivots so I had to sorta relearn how they work

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