Issue with dot product

I’m trying to make a monkey swinging system where players can swing back and fourth.

The problem is, I’m using dot products to calculate which side a player is coming from and the resulting dot product is relative to the world’s origin but not the swing’s origin(which I want to be assumed as the origin).

Video

I rapidly jump on the world’s origin to specify that 3 swings don’t work and 2 swings do.

Whenever a swing is in the -xAxis, it works, but not in the positive.

Main Issue
	local vector1 = self.Root.CFrame:PointToObjectSpace(self.Swing.Position).Unit
	local vector2 = self.Root.CFrame:VectorToObjectSpace(self.Swing.Position).Unit
	local vector3 = self.Root.CFrame.LookVector
	local product = vector1:Dot(vector3)
	print(product)
	if vector1:Dot(vector2) < 0 then
		self.Attachment1.CFrame = CFrame.Angles(0,math.rad(-90),0)
	elseif vector1:Dot(vector2) > 0 then
		self.Attachment1.CFrame = CFrame.Angles(0,math.rad(90),0)
	end

I’ve tried multiple combinations of vectors and the only things that have changed are the swings which work on the xAxis.

I’ve also tried WorldSpace but swinging from one side worked and the other didn’t. This is because the side that didn’t work just flipped me in the opposite direction.

Anything on dot products I can use to get a product relative to an object?

I found a solution, I feel like its not the best solution because I have to make every swing part face a certain direction, but if it works, it works.

	local vector1 = self.Swing.CFrame.RightVector
	local vector2 = self.Root.CFrame.LookVector
	local product = vector1:Dot(vector2)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.