How do I keep a character from looking at something when its above 90 degrees of the object using lookAt?

I’m trying to figure out how to keep a roblox character from looking at an object when they are standing above it since it causes some undesirable things.

Here is a video of what I am talking about.
https://i.gyazo.com/c716e884a2f6c9470845e10482506558.mp4

I have tried using different methods I found on the devhub, but none of the ones I found have what I am looking for. Right now I’m using CFrame.fromMatrix but I still have the problem.

The script that I made is supposed to lock onto another character with the player’s humanoidrootpart facing the character they are locking onto.

2 Likes

I’m still a little unsure what you’re talking about. What specifically is the “undesirable” behavior being shown through the link? Are you talking about the rotation of the character model about its relative x-axis (forward and backward tilt)?

It’s how the character tilts whenever they are above the object especially since it pushes them away.

How are you currently modifying the camera to get this behavior? Could I see the code snippet?

in the character there are motor6D which connect parts together did you try changing the C0 of motor6D uppertorso so that if the C0 cframe angles is greater or less than then you can do stuff

You can multiply the direction vector by Vector3.new(1,0,1) to get rid of the y axis up and down movement.

This is some of the code for the camera.

workspace.CurrentCamera.CameraType = "Scriptable"
workspace.CurrentCamera.CFrame = CFrame.new(camBlock.Position, targ.PrimaryPart.Position)
c.HumanoidRootPart.CFrame = lookAt(c.HumanoidRootPart.CFrame.p, targ.PrimaryPart.Position)

I dont know how to add the code in a reply properly so sorry about that

I have not done that yet, but I’ll see what I can do.

So like @dthecoolest said, you can multiple by Vector3.new(1,0,1) to eliminate the Y portion of a vector. In order to balance the root part, have the lookAt on a level plane:

c.HumanoidRootPart.CFrame = lookAt(c.HumanoidRootPart.CFrame.p, targ.PrimaryPart.Position*Vector3.new(1,0,1) + Vector3.new(0,c.HumanoidRootPart.CFrame.Y,0))

Three (`) characters by the way.

1 Like

Yeah I just gave his reply a try and it worked and thanks for the help with the code box.