Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to get the opposite of a vector3?

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)

2 comments

0

The opposite of a vector v is -v, it's literally that easy.

0

Not if it's a position vector. -_-

1 answer

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

1 comment

0

Sadly the Y Axis and Z Axis are inverted too

This discussion is preserved as it was. New answers, comments, and votes are closed.