Note: I’m trying not to utilize MoveTo(), MoveToPoint(), etc.
Hello!
I’m currently trying to make a dummy that mirrors a players movements, I’ve already got the dummy to look in the correct direction, but now I need it to, walk. Is there a simple way to just make it walk in one direction? Or will I have to use MoveTo() / MoveToPoint()
Or, is there just an entirely easier way to make a dummy mirror a player.
I’m trying to make the dummy copy the players movement, so if the player walks forward, the dummy walks forward, if the player walks left, the dummy walks left, etc.
Use CFrames. I am sure that there is gonna be a specific difference between the two correct? If not then still use CFrames!! How!? Well… Use Humanoid.MoveDirection! How? First of all, get what direction the player walked in using the property listed above, then before setting rotation, multiply the rigs position with said property and you’re done!
Using some of your replies, I got it to work!
Here’s the code I’m using, which bases the actual orientation of the dummy to the players orientation, well making the dummy walk in the actual direction that the player is moving in:
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local torso = character:WaitForChild("Torso")
local dummy = workspace:WaitForChild("Dummy")
local dummyHumanoid = dummy:WaitForChild("Humanoid")
game:GetService("RunService").Heartbeat:Connect(function()
local moveDirection = humanoid.MoveDirection
local moveSpeed = humanoid.WalkSpeed
dummy:SetPrimaryPartCFrame(dummy.PrimaryPart.CFrame + moveDirection * moveSpeed * game:GetService("RunService").Heartbeat:Wait())
local torsoLookVector = torso.CFrame.LookVector
local position = dummy.PrimaryPart.Position
dummy:SetPrimaryPartCFrame(CFrame.new(position, position + torsoLookVector))
end)
Thank you for all your help!
Edit: After more testing this actually didn’t work.
I realized that setting the CFrame wont work, I want it so that the dummy can have collisions and if the player jumps on a part that the dummy doesn’t have under it, it will fall, etc, meaning I will most likely have to use “MoveTo()”.
Then you could use LinearVelocity constraints set to plane mode! They respect collissions as well as gravity. You could read more about them on their documentation.
use the assemblylinearvelocity of the player you’re tracking, when they move that gets updated on the server and the NPC should move. otherwise, if you want a quicker response time, give ownership of the NPC to the player you wish to mimic it’s movement and have the player in a localscript set the dummy’s :Move() to their own MoveDirection
Thank you!
After some testing I’ve noticed this is a lot faster and more reliable then using linear velocities.
This is what I’ve ended up with:
Script in ServerScriptService:
local function setNetworkOwnerOfModel(model, networkOwner)
for _, descendant in pairs(model:GetDescendants()) do
if descendant:IsA("BasePart") then
local success, errorReason = descendant:CanSetNetworkOwnership()
if success then
descendant:SetNetworkOwner(networkOwner)
else
error(errorReason)
end
end
end
end
setNetworkOwnerOfModel(workspace:WaitForChild("Dummy"), game.Players:WaitForChild("DrDeadIy")) -- Temporary for testing
Script inside of StartCharacterScripts:
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local dummy = workspace:WaitForChild("Dummy")
local dummyHumanoid = dummy:WaitForChild("Humanoid")
humanoid.Jumping:Connect(function()
dummyHumanoid.Jump = true
end)
game:GetService("RunService"):BindToRenderStep("move", Enum.RenderPriority.Character.Value + 1, function()
dummyHumanoid:Move(humanoid.MoveDirection, false)
end)
This also works with animations! Here’s what it looks like in-game:
If anyone is wondering where how I got the dummy to have animations, theres plenty of scripts in the toolbox.