#Help Mimicking Player Movements Onto A Rig

1 messages · Page 1 of 1 (latest)

long wigeon
#

Hello! I'm including my code below. I basically want to be able to have a way for a rig to mimic a player. So if the player moves north, the rig will move north as well.

I've been attempting this all day and haven't managed to crack it. Below is my current attempt - anyone know how to deal with this or any advice?

local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local character = script.Parent

-- Wait for character to load
if not character:FindFirstChild("Humanoid") then
    character:WaitForChild("Humanoid")
end

-- Find the Copy rig
local tagged = CollectionService:GetTagged("Copy")
local copyRig = tagged[1]

-- If it doesn't exist yet, wait for it
if not copyRig then
    copyRig = CollectionService:GetInstanceAddedSignal("Copy"):Wait()
end

if not copyRig then
    warn("No Copy rig found!")
    return
end

local copyHumanoid = copyRig:WaitForChild("Humanoid")

-- Copy animations
local animator = character.Humanoid:FindFirstChildOfClass("Animator")
local copyAnimator = copyHumanoid:FindFirstChildOfClass("Animator")

if animator and copyAnimator then
    for _, track in animator:GetPlayingAnimationTracks() do
        local copyTrack = copyAnimator:LoadAnimation(track.Animation)
        copyTrack:Play()

        -- Keep syncing when new animations play
        track:GetPropertyChangedSignal("IsPlaying"):Connect(function()
            if track.IsPlaying then
                copyTrack:Play()
            else
                copyTrack:Stop()
            end
        end)
    end

    -- Handle new animations
    animator.AnimationPlayed:Connect(function(track)
        local copyTrack = copyAnimator:LoadAnimation(track.Animation)
        copyTrack:Play()

        track:GetPropertyChangedSignal("IsPlaying"):Connect(function()
            if track.IsPlaying then
                copyTrack:Play()
            else
                copyTrack:Stop()
            end
        end)
    end)
end

-- Mirror jumping
character.Humanoid.StateChanged:Connect(function(oldState, newState)
    if newState == Enum.HumanoidStateType.Jumping then
        copyHumanoid:ChangeState(Enum.HumanoidStateType.Jumping)
    end
end)

-- Mirror movement and rotation using BindToRenderStep
-- This runs AFTER the character controls, so it won't be overwritten
RunService:BindToRenderStep(
    "CopyRigMovement",
    Enum.RenderPriority.Character.Value + 1,
    function()
        -- Copy the player's rotation first
        local playerCFrame = character:GetPivot()
        local copyCFrame = copyRig:GetPivot()
        local newCopyCFrame = CFrame.new(copyCFrame.Position) * playerCFrame.Rotation
        copyRig:PivotTo(newCopyCFrame)

        -- Then apply movement in the same world direction as the player
        local moveDirection = character.Humanoid.MoveDirection

        if moveDirection.Magnitude > 0.01 then
            -- Use the player's rotation to get world-space movement
            local playerRotation = playerCFrame.Rotation
            local worldMoveDirection = playerRotation:VectorToWorldSpace(moveDirection)

            -- Apply that world direction to the copy
            copyHumanoid:Move(worldMoveDirection, false)
        else
            -- Stop movement
            copyHumanoid:Move(Vector3.zero, false)
        end
    end
)```
haughty sandBOT
#

studio** You are now Level 1! **studio

plucky dagger
#

that is to say there's a bunch of different ways you could do this

plucky dagger
#

you need humanoid for clothing to appear correctly so have that but just disable it like evalulatestatemachine=false or platformstand state

#

like cloneLeftArm.CFrame=realLeftArm.CFrame+Vector3(some_offset)

long wigeon
#

This specific iteration of it is from claude yeah, but I've been going back and forth on trying to figure out a way to do this without totally disregarding the scaffolding that's already present in the engine. My initial attempt was based on swapping the character that was parented to the actual player and creating duplicates but I wasn't able to get that working without the initial one being destroyed.

Your solution seems, just based on my intuition, like it probably isn't the easiest say since I would assume - based off of character controllers Ive worked with / made in other engines, that there's some shared piece of functionality that can be mined in order to have the NPC move exactly the same as the player.

#

Keeping track of the offset seems like it's complicating it unnessecarily, no? The thing I'm trying to shoot for is just having the inputs from the player 1-to-1 put onto a rig, where it's then moving in the same direction or jumping.

plucky dagger
#

and figuring

#

and intuiting

long wigeon
#

What is your problem brother

plucky dagger
#

instead of building

#

?

long wigeon
#

if you dont want to talk you don't need to talk

#

Can't you just be normal

plucky dagger
plucky dagger
#

give every part the same world offset and that's a duplicate of the character in a different location

#

if you want different orientation that's a different story

#

if you want to partially emulate a player-character for an npc that's yet another story

#

if you want to fully emulate a player-character in an npc that's even yet another story entirely.

long wigeon
#

That last one is what I'm trying to shoot for but just getting it to move as if it was the player is the first step in what I was wanting to make

plucky dagger
#

it works, trust

plucky dagger
long wigeon
#

I want to make a game where the player would be able to swap between controller multiple characters in one place in order to solve puzzles, like having one character parkour up to something then stand on a button or hold down a lever, then they swap to another in order to progress off of what that triggered.

plucky dagger
#

so if you parkour up to something on one character ... wouldn't the other character do exactly the same actions?

#

what's the goal here?

#

like if you have one character hold e, both characters hold e?

long wigeon
#

What I'm trying to get to work here was the first step in building that, as once I've got the character moving as if it is the player, then I can just add on the ability to swap which one is "active" and then its there.

plucky dagger
#

wait, are you trying to make a game out of the desync between the 2?

#

so like 2 rigs in a different map, one walks against a wall but the other one has no wall so keeps moving, and so they end up in different location, and you can maneouver them around like this and they have different obstances and your inputs need to work on both sides at the same time effectively? basically... a simpler version of this? https://www.youtube.com/watch?v=jNMWkD5VsZ8

After getting only a 99.8% chance of success in FireRed, I'm back in Platinum, with several billions of simulations to reclaim those pesky fractions of a percent.

⚠️WARNING: There are several points in the video where sped-up footage creates a strobe effect that may affect viewers sensitive to flashing lights. This occurs most prominently...

▶ Play video
long wigeon
#

No.

#

It's more like in Portal 2 where two characters are needed to solve puzzles in the co-op mode, except the idea would be that the player controls all of them and can swap between them.

#

So if there's a locked door that needs a button to be held down to open, they could use Character A to hold the button and then character B to walk through it.

plucky dagger
#

why is character a jumping cause character b to jump?

plucky dagger
long wigeon
plucky dagger
#

just set player.character=model on the server

#

easy Thumbs

#

roblox will conveniently reconnect everything to the new character

long wigeon
#

I already tried that, it doesn't do what I want since that destroys the old version.

plucky dagger
#

gotta love roblox's PlayerModule.lua

#

there is no old version tho

#

what, there is no destroy

#

hang on

long wigeon
#

The old player character that was the model

haughty sandBOT
#

studio** You are now Level 2! **studio

long wigeon
#

That gets destroyed

#

Becuse its replaced by the new given model

#

where what I want is that the old model is just left where it is and the player is in control of the new

#

Just changing the active character is what I already spent a few hours today trying to figure out, and it doesn't work for my case where I want the characters to remain in the world.

plucky dagger
#

ya there is no destroy

#

like just spawn a rig into workspace then run game.Players:FindFirstChildOfClass("Player").Character = workspace.*whatever.path.to.rig*

long wigeon
#

I dont think I have the code anymore as I deleted it, but when I was taking other rigs in the Workspace and then setting them as the player character the original character owned by the player was being deleted when the change happened.

plucky dagger
#

ya maybe u destroyed the player character first before setting it to a new character

#

idk but yea setting player.character to a new model does not destroy the old one

#

maybe u did that on the client and it was weird 🤷 have to do it on the server

long wigeon
#

I'll take another look at it then, might have just been frustration from trying to get it to work resulting in me being blind to the issue. I'll try a fresh run of it.

kind idol
#

You should note that using :Move() on a Humanoid through the client does not work

#

Neither does setting the jump boolean

#

I imagine that to do this lag-free, in the client, you'd have to move the copies' HumanoidRootPart s toward the Player's Character's Humanoid MoveDirection

#

I'm gonna try that now

kind idol
#

Yep, I was correct, doing this lag-free is possible through the client, but it is necessary to code physics, so the copies can't go through walls, float in the air, or jump while in the air, which is unfortunately gonna require thinking, math, and raycasts