Hello. I am trying to script a shuriken throw skill by using Spherecast for hit detection.
The problem is that even though I am adjusting the CFrame and LookVector of the shuriken (and I am shooting the Spherecast from part to its LookVector * 5) it only works accurately from one side. So what I am thinking is that I am not adjusting the LookVector correctly. I want to make it so that the shuriken’s LookVector will be wherever player was looking at before throwing it.
Here is the script:
local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Exclude
castParams.FilterDescendantsInstances = {player.Character, workspace.Debris}
local projectile = RS.Clans.Uhkia.Sakusa.SakusaSkills.NinjaStar:Clone()
projectile.Parent = debris
projectile.CFrame = character.RightHand.CFrame
projectile.CFrame = CFrame.lookAt(projectile.Position, humRP.CFrame.LookVector)
projectile:SetNetworkOwner(player)
local projectileSphere = RS.Clans.Uhkia.Sakusa.SakusaHitboxes.NinjaStarSphereCast
local projectileForce = Instance.new("BodyVelocity")
projectileForce.MaxForce = Vector3.new(1e6,1e6,1e6)
projectileForce.Velocity = humRP.CFrame.LookVector * 50
projectileForce.Parent = projectile
local hasHit = false
local direction = projectile.CFrame.LookVector * 5
while hasHit == false do
wait()
local results = workspace:Spherecast(projectile.CFrame.Position, projectileSphere.Size.X/2, direction, castParams)
if results then
hasHit = true
print(character.Name.." hit with shuriken")
projectile:Destroy()
end
end
Edit: What am I doing wrong here?