CFrame angling issue using MoveTo

Hi so I’m trying to get this dinosaur model behind this target character:


But as you can see from the above picture, the angle and the exact position is a bit messed up, I’m sure the solution is simple but the only way I tried tackling it was to use BodyGyro as apparently MoveTo is not completely accurate.

local cf = Target.HumanoidRootPart.CFrame * CFrame.new(0, 0, 3) -- Three studs behind the target's hrp.
Character.Humanoid:MoveTo(cf.p)
CFrame.lookAt(Dino.HumanoidRootPart.Position, Target.HumanoidRootPart.Position)
-- basic gist of all the CFrame stuff, not much

Would appreciate if anyone can tell me how to make it completely accurate so that the dinosaur’s humanoid root part (which is aligned correctly) is directly facing the target’s back, 3 studs away. :joy:

^ To clarify this, I mean the dinosaur, from wherever it is on the map, would have to move to the target and end 3 studs behind their back.

You are setting the Position only, but not the Rotation of the CFrame.

I see that but the position is still like a stud off, it’s not directly behind.
The rotation is handled with the lookAt.

Assuming the Character is the dino, do this:

local dinoPos, targetPos = Dino.HumanoidRootPart.Position, Target.HumanoidRootPart.Position
local backPos = dinoPos + (targetPos - dinoPos).unit * 3

Dino:SetPrimaryPartCFrame(CFrame.lookAt(dinoPos, backPos))
Dino.Humanoid:MoveTo(backPos)

Doesn’t work it just flings me back from it.

Anyone have any idea? Still can’t figure it out.

The solution seems to be in your own first post. Humanoid:MoveTo only causes the humanoid to move towards a location it’s aware of on the server. It also doesn’t rotate 100% accurately, as you said, due to some dampering.

BodyGyro is the solution you’re looking for and it’s one I personally use for combat NPCs to cause them to face the right direction. It only needs MaxTorque on the Y axis (X and Z should be 0 to avoid odd flipping on the other axes).

After the MoveTo has finished, simply have it face the correct location.

human.MoveTo.Finished:Wait()
primaryPart.BodyGyro.CFrame = CFrame.new(primaryPart.Position, target.Position)

Thanks I’ll try this out, but the BodyGyro properties confuse me, how do you get the right P, D and MaxTorque?.

I can understand Power and Dampening, but I don’t quite get the torque and maxtorque element.

The simplest answer is: You don’t really know.

The MaxTorque must be able to move the mass of the assembly system (the connected parts of the root part) and the power (P) is how much force to apply to rotate the part to the designated goal. In short, you have to play around with these numbers in the live game and find some that satisfy your needs.

Almost never will you need to adjust the dampening (D). Start with a relatively high MaxTorque on the Y axis (something like 40000) and play with the power.

1 Like

It’s still not centered but the BodyGyro seems to be a start, what could the possible reason be for it not being completely straight? The position of the Dinosaur’s HRP would be exactly 3 studs from the target’s HRP yet it doesn’t seem to be working.

I can’t decipher from just words, unfortunately. To protect your model’s proprietary design, could you remove the meshes or the mesh IDs and provide me a reproduction I can test in my own place? It can better serve as a diagnosis. Because I am able to get this working with my own test model no issues.

The thing is in studio it works fine, it seems the MoveTo actually has the position off too I think?

Sorry, I’m not sure how those screenshots relate to the rotation?

I’m showing that by setting the CFrame how I currently am (CFrameValue.p) within the MoveTo method seems to mess it up, this works no matter which way I’m facing.

Here’s my current BodyGyro stuff:

Parent = Dinosaur PrimaryPart (HumanoidRootPart)
Power = 20000
Dampening = 50
MaxTorque = Vector3.new(0, 40000, 0)

If you add me on discord I’ll try send you the model Kakashi#0001

I’ll shoot you over my setup and you can compare it to your own. I’ve also attached the place file and a video demo below.

image

followTest.rbxl (24.0 KB)

Utterly confused… when replacing the model with my own in your script it works perfectly lol…
Is there some difference when you use it in a server script? Afaik my code is identical to yours, but in a clientscript.

In the words of Khanovich, I am confused as to why you are trying to move a Humanoid on the client. This only works when you are near it and otherwise has null behavior or improper behavior because its NetworkOwnership phases in and out. Shown below.

1 Like


:man_facepalming: :man_facepalming:

Alright so I’m using a RemoteFunction to the server to do the MoveTo now, it seems a bit buggy and the end position is still wrong:
image

        if Action == "PounceTarget" then
            local EndPosition = Args[2].CFrame * CFrame.new(0, 0, 3)
            Args[1].Parent:WaitForChild("Humanoid"):MoveTo(EndPosition.Position)
            Args[1].Parent:WaitForChild("Humanoid").MoveToFinished:Wait()
            Args[1].BodyGyro.CFrame = CFrame.new(Args[1].Position, Args[2].Position)
            return true
        end

Args[1] is the Dinosaur’s HRP and Args[2] is the target’s HRP.

Sorry, I can’t really give much help from speculation. If you could provide a reproduction place or model that would be optimal. Because something unseen is clearly affecting this given my example works.