Troubles setting tool's position

When I throw the frisbee, I make it spawn a little bit in front of the player. In the video you can see the problem, which is that when I am running forward and throw, the frisbee spawns behind me and hits me in the back. When I stand still, it works as expected and when I run backwards, it spawns further away from me. I make it so the player can’t move and any existing velocity on the player is removed to try to prevent this. You can see I print the players position and the spawnPos (spawn position of frisbee) and they are always the same. With them being the same, I thought it would work as expected, but clearly it does not.

function shot(direction)
	brake=true
	animationInProgress=true
	
	local directionMultiplier=1
	local vectorForceApplied=0
	
	
	
	local character=frisbee.Parent
	
	character:WaitForChild("Humanoid").WalkSpeed=0
	character.primaryPart.AssemblyLinearVelocity = Vector3.zero
	character.primaryPart.AssemblyAngularVelocity = Vector3.zero 
	
	print(character:WaitForChild("HumanoidRootPart").CFrame.Position)
	
	local player= game.Players:GetPlayerFromCharacter(character)
	local humanoid=character:FindFirstChild('Humanoid')
	local spawnPos = CFrame.new(character:WaitForChild("HumanoidRootPart").CFrame.Position)
	
	print(spawnPos)
	
	--find target point
	local mouseHit = game.ReplicatedStorage.getMouseLocation:InvokeClient(player)
	local angle=math.atan((mouseHit.Z-spawnPos.Z)/(mouseHit.X-spawnPos.X))

	local x=math.cos(angle)
	local z=math.sin(angle)
	print(math.deg(angle))
	--determine power level
	if bluePerfects==3 and b==-1 or redPerfects==3 and b==1 then
		x=x*300
		z=z*300

		if b==1 then
			redPerfects=0
		elseif b==-1 then

			bluePerfects=0
		end

	elseif timer<.1 then
		x=x*blue
		z=z*blue
		keypoints=greyKeypoints
		print("early")
	elseif timer<purpleWindow then	
		x=x*purple-((.1/timer)*50)
		z=z*purple-((.1/timer)*50)
		keypoints=purpleKeypoints

		if b==1 then
			redPerfects+=1	


		elseif b==-1 then

			bluePerfects+=1	

		end

	elseif timer <blueWindow then
		print("bluex="..x)
		x=x*blue-((purpleWindow/timer)*35)
		z=z*blue-((purpleWindow/timer)*35)
		keypoints=blueKeypoints

	elseif timer<grayWindow then
		x=x*gray-((blueWindow/timer)*20)
		z=z*gray-((blueWindow/timer)*20)
		keypoints=greyKeypoints

	else
		x=x*50
		z=z*50
		keypoints=greyKeypoints
	end

	print("timer=" ..timer)
	playAnimation(character)
	wait(.25)
	mesh:Destroy()
	if intermediate then
		intermediate:Destroy()
	end
	
	--set velocity
	frisbee.Parent=game.Workspace
	frisbee.Handle.CFrame=CFrame.new(spawnPos.X+(b*5),3.997,spawnPos.Z)
	frisbee.Handle.AssemblyLinearVelocity=Vector3.new(x*b,0,z*b)

	
	print("x="..x)
	print("z="..z)

	--Curve
	
	
	if direction=="right" or direction=="left"then 
		
		if direction=="right" then
			directionMultiplier=-1
		end
		vectorForceApplied=-1*directionMultiplier*b*math.abs(math.deg(angle)*20)
		if math.abs(vectorForceApplied)>maxVectorForce then
		vectorForceApplied=-maxVectorForce*b
		end
	vectorForce.Force=Vector3.new(0,0,vectorForceApplied)
	vectorForce.Enabled = true
	print("vector force=")
		print(vectorForceApplied)
		
		end
--intermediate
	intermediate=Instance.new("Part")
	intermediate.Name="Intermediate"
	intermediate.Parent=body
	intermediate.CFrame=body.CFrame
	if direction=="right" or direction=="left"then
		intermediate.Orientation=Vector3.new((vectorForceApplied/maxVectorForce)*45,0,0)
	else
		intermediate.Orientation=Vector3.new(0,0,0)
	end


	local weld = Instance.new("WeldConstraint")
	weld.Parent = intermediate
	weld.Part0 = body
	weld.Part1 = intermediate

	intermediate.Transparency=1
	intermediate.CanTouch=false
	intermediate.CanCollide=false
	intermediate.Massless=true

	local rotationAttachment=Instance.new("Attachment")
	rotationAttachment.Name="RotationAttachment"
	rotationAttachment.Parent=intermediate
	rotationAttachment.Orientation=Vector3.new(0,180,90)






	--apply frisbee skin
	mesh=game.ReplicatedStorage.Frisbees.tronfrisbee:Clone()
	mesh.CustomPhysicalProperties=PhysicalProperties.new(.1,0,0)
	mesh.CanTouch=false
	mesh.CanCollide=false
	mesh.Massless=true
	mesh.Position=intermediate.Position
	mesh.Size=Vector3.new(5,5,1)
	mesh.Parent=body


	local hinge = Instance.new("HingeConstraint")
	hinge.Parent = intermediate
	hinge.Attachment0 = rotationAttachment
	hinge.Attachment1 = mesh.Attachment

	hinge.ActuatorType="Motor"
	hinge.AngularVelocity=-15*b
	hinge.MotorMaxAcceleration=15
	hinge.MotorMaxTorque=15
	
	
	--stop spin
	frisbee.Handle.AlignOrientation.Enabled=true

	--set network ownership
	for i,v in pairs(frisbee:GetDescendants()) do
		if v:IsA("BasePart") then
			v:SetNetworkOwner(nil)
		end
	end
	
	
	--Trail
	--(0,0,+-2.5)
	local trailAttachment1=Instance.new('Attachment')
	local trailAttachment2=Instance.new('Attachment')
	trailAttachment1.Parent=intermediate
	trailAttachment2.Parent=intermediate
	trailAttachment1.Position=Vector3.new(0,0,2.5)
	trailAttachment2.Position=Vector3.new(0,0,-2.5)
	trail.Attachment0=trailAttachment1
	trail.Attachment1=trailAttachment2

	trail.Enabled=true
	trail.Color= ColorSequence.new(keypoints)
	if keypoints==purpleKeypoints then
		trail.Lifetime=.5
	else 
		trail.Lifetime=.3
	end
	
	--Set collision group
	frisbee.Handle.Body.CollisionGroup='frisbee'
	for _, v in pairs(character:GetChildren()) do
		if v:IsA("Basepart") then
			v.CollisionGroup = "None"
		end
	end
	frisbee.Handle.Body.CanTouch=false
	frisbee.Handle.CanTouch=false
	wait(.3)
	for _, v in pairs(character:GetChildren()) do
		if v:IsA("Basepart") then
			v.CollisionGroup = "Default"
		end
	end
	frisbee.Handle.Body.CanTouch=true
	frisbee.Handle.CanTouch=true
	


	
	character:WaitForChild("Humanoid").WalkSpeed=40
	animationInProgress=false
end
1 Like

It looks like you’re just spawning it with a slight modification to the X vector, but I believe you should be taking the LookVector into account. You should try adding the humanoidRootPart.CFrame.LookVector (or Head) to that CFrame call i quoted above.

1 Like

It shouldn’t matter which direction I’m looking though. If I stand still and turn around the frisbee works as intended. To be clear, I only want it going in the positive x direction.

It looks like you are using CFrame ToWorldSpace instead of ToObjectSpace.

What happens when you throw the frisbee left or right? The video only shows you throwing away from or to the camera.

The frisbee can be aimed left or right and it will go in that direction. I coded it so that there is a minimum angle that the frisbee can be thrown at so it will always be making progress in the positive X direction. Like I said, I don’t want it to travel in the direction I’m facing, I want it to travel in the positive X direction.