I am trying to make some sort of basic underwater AI, and because it’s underwater I can’t use Pathfinding service or MoveTo() because they can’t go down in water. Anyway, I’m trying to apply a body gyro and a body thrust, but its not moving or rotating in the direction it should be
local dest = Vector3.new(math.random(-speed,speed),math.random(-speed,speed),math.random(-speed,speed))
local orientation = CFrame.lookAt(humanoidRootPart.Position,humanoidRootPart.Position + dest)
orientation = orientation.LookVector
humanoidRootPart.BodyGyro.CFrame = CFrame.Angles(orientation.X,orientation.Y,orientation.Z)
humanoidRootPart.BodyThrust.Force = dest
I’m not very good with CFrames/body movers, so it completely confuses me why they move the model just not in the right direction.
You don’t have to use the LookVector for BodyGyros. They can take any raw CFrame, they just ignore the position. The reason this isn’t working right now is because you’re creating a new CFrame using the LookVector as angles for CFrame.Angles. LookVector is more of a unit vector that tells the facing direction of something while CFrame.Angles expects three angle inputs in radians, as if you were setting the orientation of something using radians instead of degrees. This should work:
local dest = Vector3.new(math.random(-speed,speed),math.random(-speed,speed),math.random(-speed,speed))
local orientation = CFrame.lookAt(humanoidRootPart.Position,humanoidRootPart.Position + dest)
humanoidRootPart.BodyGyro.CFrame = orientation
humanoidRootPart.BodyThrust.Force = dest
Anyway, this does rotate the model, but the rotation is still not synced up to the body thrust movement, which leads to this weird situation where the model will turn and then just start moving in some completely different direction.
This sounds like a classic problem where the front side of the model isn’t actually the front face in Roblox, in that case you can just rotate the orientation variable until it matches up. Try this:
local orientation = CFrame.lookAt(humanoidRootPart.Position,humanoidRootPart.Position + dest) * CFrame.Angles(0, math.rad(90), 0)
If it’s still wrong, try switching out the 90 with 180 or 270. And if that fails, try using math.rad on other axes instead, it might not be the y-axis that’s rotated wrong. That’s just the most commonly messed up axis for facing direction issues.
BodyThrust is kind of odd, I never really worked with them. I usually use BodyVelocity for this sort of thing. If you make a BodyVelocity and set its velocity to the orientation.LookVector * (some speed) then it should work.