I'm trying to make my monster look at the player's torso while following them (This is a custom monster no humanoid) but i want it to only use X and Z i want it to the ignore the Y coordinate is that even possible.
I tried using bodygryo it focuses on the player, But only on the part left surface it completely ignore's the front surface?
1 | -- hmr is the monster's torso |
2 | -- torso is the player's |
3 | hmr.CFrame = CFrame.new(hmr.Position,torso.Position.X,torso.Position.Z) |
error
1 | Invalid number of arguments: 4 |
You can use CFrame's lookAt
parameter to make the monster look at the human's torso position. Because you set the y position to be 5, the monster will always be looking at the height of 5.
1 | local customPosition = Vector 3. new(torso.Position.X, 5 , torso.Position.Z) |
2 | hrp.CFrame = CFrame.new(hrp.CFrame, customPosition ) |
What the lookAt parameter is doing:
1 | function lookAt(target, eye) |
2 | local forwardVector = (eye - target).Unit |
3 | local upVector = Vector 3. new( 0 , 1 , 0 ) |
4 | -- You have to remember the right hand rule or google search to get this right |
5 | local rightVector = forwardVector:Cross(upVector) |
6 | local upVector 2 = rightVector:Cross(forwardVector) |
7 |
8 | return CFrame.fromMatrix(eye, rightVector, upVector 2 ) |
9 | end |