CFrame.lookat() results in misplacing the part

A chaser part is supposed to tp to the last position of the humanoid and then face it properly, for some reason it gets misplaced after setting the cframe lookvector


if victim then
			char.CFrame = CFrame.new(position + Vector3.new(0,9,0))
			char.CFrame = CFrame.lookAt(script.Parent.Position, Vector3.new(victim.Torso.Position.X, script.Parent.Position.Y,victim.Torso.Position.Z))
			chasing = false
		end

1 Like

Hey, There! I guess the problem is Initial Positioning and Incorrect Target Position so if we want to change this. First calculate the Correct Target Position

 local targetPosition = Vector3.new(victim.Torso.Position.X, script.Parent.Position.Y, victim.Torso.Position.Z)

To set the initial position of the char part. and places the char part 9 units above the given position

also Setting the CFrame to Face the Target Position

char.CFrame = CFrame.lookAt(script.Parent.Position, targetPosition)`

To make the char part face the targetPosition also Sets the CFrame of the char part to look at the targetPosition

Lastly, Initial Positioning

we keep everthing same

char.CFrame = CFrame.new(position + Vector3.new(0, 9, 0))

Full code Should be like this

if victim then
    char.CFrame = CFrame.new(position + Vector3.new(0, 9, 0))
    local targetPosition = Vector3.new(victim.Torso.Position.X, script.Parent.Position.Y, victim.Torso.Position.Z)
    char.CFrame = CFrame.lookAt(script.Parent.Position, targetPosition)
    chasing = false
end

Doesn’t work, for context the position variable is the hrp position, its a little messsed up. Im trying to save the hrp position so it isnt updated constantly, for the tp to be with a slight delay so the chaser can catch you only if you stand still