I have a pet system I am currently working on, and it’s going well currently, except for one small detail.
Depending on which axis my character is facing, the pet will float either slightly in front or slightly behind me, as seen below.
I want it to be slightly behind me at all times. How would I do this? Attached is my code:
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local clone = game.ServerStorage.Duck:Clone()
local posHolder = Instance.new("AlignPosition",clone.PrimaryPart)
posHolder.MaxForce = math.huge
posHolder.Mode = Enum.PositionAlignmentMode.OneAttachment
posHolder.Attachment0 = clone.PrimaryPart.Attachment
local gyro = Instance.new("AlignOrientation",clone.PrimaryPart)
gyro.Mode = Enum.OrientationAlignmentMode.OneAttachment
gyro.Attachment0 = clone.PrimaryPart.Attachment
gyro.MaxTorque = math.huge
clone.Parent = char
while wait() do
posHolder.Position = char.PrimaryPart.Position + Vector3.new(0,1,2)
gyro.CFrame = char.PrimaryPart.CFrame
end
Code isn’t the best right now, currently in the very early stages of this system and I’m more focused on getting the basics down
astraIboy
(The Batman)
April 19, 2024, 8:27pm
#2
Try this
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local clone = game.ServerStorage.Duck:Clone()
local posHolder = Instance.new("AlignPosition",clone.PrimaryPart)
posHolder.MaxForce = math.huge
posHolder.Mode = Enum.PositionAlignmentMode.OneAttachment
posHolder.Attachment0 = clone.PrimaryPart.Attachment
local gyro = Instance.new("AlignOrientation",clone.PrimaryPart)
gyro.Mode = Enum.OrientationAlignmentMode.OneAttachment
gyro.Attachment0 = clone.PrimaryPart.Attachment
gyro.MaxTorque = math.huge
clone.Parent = char
while task.wait() do
posHolder.Position = char.PrimaryPart.CFrame.Position + char.PrimaryPart.CFrame.LookVector * -2 + char.PrimaryPart.CFrame.UpVector * 1
gyro.CFrame = char.PrimaryPart.CFrame
end
1 Like
Yep, this works! Thank you so much for such a fast reply!
1 Like
astraIboy
(The Batman)
April 19, 2024, 8:29pm
#4
Also I can explain why it works aswell its because before you were using world space coordinates which are relative to the world, but I changed to be relative to the axis the player is facing which will make it always be behind, your welcome!
1 Like
system
(system)
Closed
May 3, 2024, 8:29pm
#5
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.