Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to get the opposite of a vector3?

Asked by 4 years ago

Hello, im trying to make a cannon that kills people automatically but it rotates to the opposite of the torso's position, how can i get the opposite of it, like if its pointing to the south, point to the north This is the code im using :

local debounce = false
script.Parent.area.Touched:Connect(function(c)
    if script.Parent.Auto.Value then -- auto is a bool value
    if c then
        if c.Parent then
            if c.Parent ~= workspace then
                if c.Parent:FindFirstChildOfClass("Humanoid") or game:GetService("Players"):GetPlayerFromCharacter(c.Parent) then

                    if not debounce then
                        local torso
                        if c.Parent:FindFirstChild("Torso") then
                            torso = c.Parent:FindFirstChild("Torso") 
                        elseif c.Parent:FindFirstChild("UpperTorso") then
                            torso = c.Parent:FindFirstChild("UpperTorso")
                        end
                        if torso then
                        debounce = true
                        local goal = CFrame.new(script.Parent.Cannon.PrimaryPart.Position,Vector3.new(torso.Position.X,script.Parent.Cannon.PrimaryPart.Position.Y,torso.Position.Z))
                        for i = 0,100,0.2 do
                            if script.Parent.Cannon.PrimaryPart.CFrame == goal then
                                break
                            end
                            local posTo = script.Parent.Cannon.PrimaryPart.CFrame:Lerp(goal,i/100)
                            script.Parent.Cannon:SetPrimaryPartCFrame(posTo)
                            wait(0.01)

                        end
                        script.Parent.Cannon.Model.pew.Transparency = 0
                        wait(1)
                        script.Parent.Cannon.Model.pew.Transparency =1
                        wait(2)
                        debounce = false
                        end
                    end
                end
            end
        end
    end
    end
end)
0
The opposite of a vector v is -v, it's literally that easy. EmilyBendsSpace 1025 — 4y
0
Not if it's a position vector. -_- Humanagon 5 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

to get a vector that is opposite of another it's just as easy as -vector, but in your case the vector3 is a position vector in workspace, you need a direction which is basically FinalPosition - torso.Position but the opposite of it would be -(FinalPosition - torso.Position) or straight up torso.Position - FinalPosition hopefully this answers your question

0
Sadly the Y Axis and Z Axis are inverted too maumaumaumaumaumua 628 — 4y
Ad

Answer this question