How can I align a Player towards another Player?

I tried using the code below but it kept on doing this: https://gyazo.com/11561a412722252b648499f7d9d15c6f
https://gyazo.com/e661178a534672b4f38b5300e1331000
https://gyazo.com/25d8b441a5e60542a8158398c7494df4

  PlayersHRP.CFrame = CFrame.new(PlayersHRP.Position, TargetsHRP.Position)
  --PlayersHRP is the Player's humanoid root part, TargetsHRP is the humanoid root part that the player is trying to align its Y axis to.

The goal is to align the players towards the another player while also allowing them to move freely(while still keeping them faced towards the other player). All answers are appreciated.

You could try a BodyGyro or AlignPosition. I wanna say that a lot of HumanoidRootPart CFraming gets overwritten by the player’s Control Script unless bound to RenderStepped.

I should mention that even with a physics mover, though, that players in first-person will still always face the direction of the camera unless a bigger work-around is used.

1 Like

How would I be able to use BodyGyro to achieve my goal?

Did you add this in a loop or RenderStepped.

I still wan’t the player to be able to move while facing the opposing player. The player won’t be able to move if I use a loop/RenderStepped.

Try this

-- BodyGyro should be inside PlayersHRP
BodyGyro.CFrame = CFrame.new(PlayersHRP.Position, TargetsHRP.Position)

https://gyazo.com/5615cb752164c112db31de3158f9e678
This is what happens if you put the code inside a loop.

also set it’s torque to to 0, 10000, 0

https://gyazo.com/25527fe3709c9ece94fea71149f6f0be
It works, but it doesn’t turn the player fast enough. Is there any way for it to snap to the player at a faster speed?

try increasing the torque so 0,30000,0 for example

1 Like

It still doesn’t turn fast enough or me. :frowning:

Make to torque higher until its fast enough.

If the assembly is moving too slowly, consider lowering the D (dampening) property. Also consider raising the MaxTorque and/or P (power) properties. According to this.

https://gyazo.com/fcab81226120772af95b698b23484b81
It works, but is this only way to achieve this effect, or are there more effective methods?

You could use AlignPosition.

Can you explain how would I could use AlignPosition to achieve my goal?

In this video, the pet moves with the same orientation and position(Reduced).

robloxapp-20200927-1236069.wmv (3.1 MB)

Here’s the example code for your goal:

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        
        wait(5)
        
        local attachment1 = Instance.new("Attachment");
        attachment1.Parent = Character.HumanoidRootPart;
        attachment1.Position = Character.HumanoidRootPart.Position - Vector3.new(0, -2, -3)
        
        local attachment0 = Instance.new("Attachment", workspace.Pet) -- I have a square named "Pet" in the workspace.
        
        workspace.Pet:SetNetworkOwner(Player)
        
        local alignPosition = Instance.new("AlignPosition", workspace)
        local alignOrientation = Instance.new("AlignOrientation", workspace)
        alignOrientation.Attachment0 = attachment0 -- Attachment 0's orientation will be the same as attachment 1.
        alignOrientation.Attachment1 = attachment1
        alignOrientation.MaxTorque = 25000
        alignPosition.MaxForce = 25000
        alignPosition.Attachment0 = attachment0 -- Attachment 0's position is the attachment 1
        alignPosition.Attachment1 = attachment1
        
    end)
end)

I hope that solves your problem

Check this out.

I’ll check that out right now, if it works better then the BodyGyro method, i’ll make this the new solution. :slight_smile:

1 Like