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