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)
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