I have a blender made character that I imported into Roblox Studio, and the root part is facing the wrong way. This character faces the player to attack them, but because the root part is inverted, they face the opposite way. Is there a way to somehow invert lookAt so it looks in the opposite direction of what it’s supposed to?
Check out CFrame:Inverse() - Creator Docs.
How exactly would I implement this into lookAt
CFrame.lookAt(myCFrame, faceTowardsCFrame):Inverse()
I tried this, and it didn’t work. Here is my original code.
local lookat = CFrame.lookAt(script.Parent.Position, Child.Position, script.Parent.CFrame.UpVector)
script.Parent.CFrame = script.Parent.CFrame:Lerp(lookat, 10/numOfSteps)
I need the extra stuff because if I don’t smooth out the LookAt it looks dumb, because the character is very big.
I think you could just rotate the CFrame by 180 degrees with CFrame.Angles, pretty sure inverse would also invert the cframe’s position
Yeah I forgot about that, if you invert the vector you want to look at it should be fine.
local lookat = CFrame.lookAt(script.Parent.Position, -Child.Position, script.Parent.CFrame.UpVector)
script.Parent.CFrame = script.Parent.CFrame:Lerp(lookat, 10/numOfSteps)
Does this work?
Or:
local lookat = CFrame.lookAt(script.Parent.Position, Child.Position, script.Parent.CFrame.UpVector) * CFrame.Angles(0, math.rad(180), 0)
script.Parent.CFrame = script.Parent.CFrame:Lerp(lookat, 10/numOfSteps)
It puts out an error “Inverse is not a valid member of vector 3”
CFrame.LookAt(CFRAMESTUFFHERE)*CFrame.FromEulerAngles(0,math.rad(180),0)
Yeah just do this.
Inverse should be for CFrame (put it outside of the LookAt)
I think you’re supposed to change the LookAt Vector3 to a CFrame and inverse it, then turn it back into a Vector3
Rotating the thing works, but because I’m tweeting the look at, its turning around faster than the look at is looking at me. So its just spinning rapidly. I would have to incorporate it into the tween somehow.
Are you also using a tween? Lerping it should be fine.
In that case, you can add lerping and put it inside some sort of loop
while task.wait() do --make sure this is put at the bottom or in a new thread so it doesn't indefinitely pause any lines under it
PART.CFrame:Lerp(CFrame.LookAt(CFRAMESTUFFHERE)*CFrame.FromEulerAnglesXYZ(0,math.rad(180),0),0.05)
end
Also if the NPC is constantly moving around, I think you should use a BodyGyro to change the rotation instead
In your tween, multiply by CFrame.Angles(0, math.rad(180), 0)
.
e.g
tweenService:Create(part, tweenInfo, {CFrame = targetCFrame * CFrame.Angles(0, math.rad(180), 0)}:Play()
There are no tweens. Its only lerping, I meant tweeting as in smooth. I tried manually inverting the position and just using that instead, but then it just didn’t look at me for some reason.
local InvertedPosition = Vector3.new(-Child.Position.X, -Child.Position.Y, -Child.Position.Z)
local lookat = CFrame.lookAt(script.Parent.Position, InvertedPosition, script.Parent.CFrame.UpVector)
script.Parent.CFrame = script.Parent.CFrame:Lerp(lookat, 10/numOfSteps)
Body gyro was removed/deprecated
local lookat = CFrame.lookAt(script.Parent.Position, -Child.Position, script.Parent.CFrame.UpVector)
script.Parent.CFrame = script.Parent.CFrame:Lerp(lookat, 10/numOfSteps)
(This won’t fix it but is more readable)
Could you send a video of the error or a picture?
Being deprecated doesn’t mean much; it just means there’s better options
I use it for my NPCs and other stuff
It wouldn’t let me upload the video, but it basically just swims in a single random direction, and it doesn’t change wether I change my position or not.