AlignPosition & Orientation Help

Hello, I’m making a Star Wars game and would like to make a system where you can buy droids to follow you around. I am currently using AlignPosition and AlignOrientation to get the droids to follow their owners around.

However, there are still some bugs such as I need help fixing, specifically:

  • Droid not interacting with environment correctly (e.g part collisions)
  • Not sure how to add offset so the droid isn’t inside the player’s leg
  • And how would I correctly use AlignOrientation correctly to get the droid to rotate the correct way?

Code is below, I am using PlayerAdded for now for convenience.

game.Players.PlayerAdded:Connect(function(Player)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	
	local Droid = game.ServerStorage.Astromech:Clone()
	Droid.Parent = Character
	
	local PlayerAttach = Character:WaitForChild("RightLowerLeg"):WaitForChild("RightAnkleRigAttachment")
	local PartAttach = Droid:WaitForChild("Main"):WaitForChild("Attachment")
	
	local AlignPosition = Instance.new("AlignPosition")
	AlignPosition.Parent = Character:WaitForChild("RightLowerLeg")
	AlignPosition.Attachment0 = PartAttach
	AlignPosition.Attachment1 = PlayerAttach
	
	local AlignOrientation = Instance.new("AlignOrientation")
	AlignOrientation.Parent = PlayerAttach
	AlignOrientation.Attachment0 = PartAttach
	AlignOrientation.Attachment1 = PlayerAttach
end)
1 Like
game.Players.PlayerAdded:Connect(function(Player)
	local Character = Player.Character or Player.CharacterAdded:Wait()

	local Droid = game.ServerStorage.Astromech:Clone()
	Droid.Parent = Character

	local PlayerAttach = Character:WaitForChild("RightLowerLeg"):WaitForChild("RightAnkleRigAttachment")
	local PartAttach = Droid:WaitForChild("Main"):WaitForChild("Attachment")

	local AlignPosition = Instance.new("AlignPosition")
	AlignPosition.Parent = Character:WaitForChild("RightLowerLeg")
	AlignPosition.Attachment0 = PartAttach
	AlignPosition.Attachment1 = PlayerAttach
	
	local AlignOrientation = Instance.new("AlignOrientation")
	AlignOrientation.Parent = PlayerAttach
	AlignOrientation.Attachment0 = PartAttach
	AlignOrientation.Attachment1 = PlayerAttach
	
	Character:SetAttribute("DroneFollow", true)
	
	local droneFollow = true
	
	while droneFollow do
		droneFollow = Character:GetAttribute("DroneFollow")
		
		local HRP = Character.HumanoidRootPart
		
		local behindPosition = HRP.Position - (HRP.CFrame.LookVector * 5)
		PlayerAttach.WorldCFrame = CFrame.new(behindPosition, HRP.Position)
		wait(0.1)
	end
end)

here is an updated version that fixes the issue of the droid being inside the player, looking at the orientation issue now.

You would just need to change the attachment position inside the droid:

Old:

image

New:

1 Like