How to remove all player momentum

If I am running forward and throw my frisbee, it spawns behind me and hits me in the back. I want to get rid of all player momentum before the spawn position of the frisbee is determined. I try to make it spawn 5 studs in front of me. You can see the 4 times I print a message and this is what I get:
22:07:47.368 80.41546630859375, 3.679743766784668, 339.53314208984375 - Server - Frisbee Script:138
22:07:47.368 80.4154663, 3.67974377, 339.533142, 1, 0, 0, 0, 1, 0, 0, 0, 1 - Server - Neer Frisbee Script:144
22:07:47.668 85.4154663, 3.99699998, 339.533142, 1, 0, 0, 0, 1, 0, 0, 0, 1 - Server - Frisbee Script:216
22:07:47.668 88.86921691894531, 3.679743766784668, 339.8255310058594 - Server - Frisbee Script:217

The first 3 CFrames are what I expect, but the last one shows that the player has moved beyond the spawn position. In this case, I only want the frisbee to travel in the positive X direction.

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	
			shotFeedback(redPerfects)

		elseif b==-1 then

			bluePerfects+=1	
			shotFeedback(bluePerfects)

		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(CFrame.new(spawnPos.X+(b*5),3.997,spawnPos.Z))
	print(character:WaitForChild("HumanoidRootPart").CFrame.Position)
	--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="..vectorForceApplied)
		
		
		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
player.Character.HumanoidRootPart.Velocity = 0

I think its

player.Character.HumanoidRootPart.Velocity = Vector3.New(0, 0, 0) actually.

I think the problem is that you have a wait() and InvokeClient() between when the frisbee is fired and when the spawn position is determined.

Try moving the code that determines the spawn position and target point until after the animation. Then declare the spawn position only after the client returns with the mouse’s location.

  • Instead of creating a new post, bump the old post

  • Use fast cast to fix spawn delay

  • You could always use move direction to predict the spawn position, but if you want the player to stay still then you could have an external force or anchor the player.

1 Like

Same result unfortunately------

1 Like

This shouldn’t matter though. I get the spawnPos (theoretically) right after the player stops moving and then later I add 5 studs to make it spawn infront of the player. In that time the player shouldn’t be moving because I set walkspeed to 0 and removed all velocity. I could have a wait(5000) between the two and it should still work the same.

I have a new revelation aswell. I printed the velocity after setting it to 0 and anchoring the player and it turns out the player still has a little velocity somehow.

character.HumanoidRootPart.Velocity = Vector3.zero
	character.HumanoidRootPart.AssemblyAngularVelocity = Vector3.zero 
	character.HumanoidRootPart.Anchored=true
	
	print(character.HumanoidRootPart.Velocity)
	print(character:WaitForChild("HumanoidRootPart").CFrame.Position)
	
	local player= game.Players:GetPlayerFromCharacter(character)

this is what it prints
0.10606641322374344, 0, -0.016173535957932472

Use collision groups, they allow you to make it so specific objects can’t collide with other specific objects. In this case, you don’t want the frisbee to collide with the character, so you’d make 2 collision groups:

1 group for your character, and 1 group for your frisbee.

You’d need to script the character so any BaseParts inside the character are set to your character’s collision group, and you’d need to set the frisbee’s collision group too

btw collision groups seem complicated at first (mostly because of the UI looking confusing) but they’re extremely helpful and it’s worth looking into how they work

Actually, it does matter. There is a delay between when the server tells the client to stop moving, and when the client recieves that command. Have you tried my suggestion?

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