Turning Model Ends Up Being Random... I Think?

I’m working on a game where a character that is not the player moves through a map in a specific path. The character can not be moved manually and will stick to it’s path.

I ran into a problem while coding, I used AlignOrientation to Rotate the Character so that it faces where it is moving, but the map is self generating and I cannot predict the next point it must move towards.

So I made a script that rotates the next point as soon as it is created so that the rotation is facing opposite the previous point, meaning the Character will face the next point while moving towards it.

//PROBLEM//

The problem is when the point is rotated it doesn’t rotate as expected and instead is either offset by a little or entirely wrong.

//The Code//

Pos01 is the position of the previous point
NewArea is the next area that will be added to the map
StartPos is the next point

		local Pos01 = game.Workspace.Areas["Plane"..game.Workspace.Areas.HighestArea.Value].EndPos.Position
		newArea.StartPos.CFrame = CFrame.lookAt(newArea.StartPos.Position,Vector3.new(newArea.StartPos.Position.X,Pos01.Y + 180,newArea.StartPos.Position.Z))
		newArea.StartPos.Orientation = Vector3.new(0,newArea.StartPos.Orientation.Y,0)

//END//

Thank You in advance to whoever helps, and sorry for my confusing code.

2 Likes