Ad
Log in to vote
0

How to change LookVectors into a sideways version of themselves?

Asked by
popsi_le 102
1 month ago

I'm trying to make a pet system, but I need to offset some of the pet's positions to fit more than one. Subtracting Vector3s from the position resulted in an offset based off of the player's angle, which is not what I wanted to make. Here is my current script:

local ss = game:GetService("ServerStorage")
local runs = game:GetService("RunService")

local pets = ss:WaitForChild("Pets")
local defaultPet = pets:WaitForChild("Noob")

local dist = 9

function givePet(plr,pet)
    if plr then
        local char = workspace:FindFirstChild(plr.Name)
        if char then
            local hrp = char.HumanoidRootPart
            local newPet = pet:Clone()
            newPet.Parent = char

            local bodyPos = Instance.new("BodyPosition",newPet)
            bodyPos.MaxForce = Vector3.new(math.huge,math.huge,math.huge)

            local bodyGyro = Instance.new("BodyGyro",newPet)
            bodyGyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)

            runs.Stepped:Connect(function()
                bodyGyro.CFrame = hrp.CFrame
                bodyPos.Position = hrp.Position + -hrp.CFrame.LookVector*dist
            end)
        end
    end
end

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function()
        workspace:WaitForChild(plr.Name)
        spawn(givePet(plr,defaultPet))
    end)
end)

1 answer

Log in to vote
1
Answered by 1 month ago

Use CFrame.RightVector, if you want it to go left multiply by negative one. https://developer.roblox.com/en-us/api-reference/datatype/CFrame

Ad

Answer this question