-
What do you want to achieve? make the knife rotate and facing where is the destination
-
What is the issue? i cant make the knife rotate or well i dont know where i start, everything is working tough but i dont know how to rotate the knife (the vizualize thing)
-
What solutions have you tried so far? i try to see some post in this forum but how i say before i dont know where i Begin
here a clip of how its works
i made the script and the projectile by following a yt tutorial, he doesnt explain or make a properly projectile vizualizer. here the yt video: https://youtu.be/279r8beQPeE?si=aJd_uS5LDPQMVhS5
-- local run = game:GetService("RunService")
local debris = game:GetService("Debris")
local projectile = {}
function projectile.New (gravity, whitelist, wind, despawntime, visualize)
local newproject = {}
newproject.Gravity = gravity
newproject.Wind = wind
newproject.DespawnTime = despawntime
newproject.Visualize = visualize
local part = game.ServerStorage.knifeme
local clo = part:Clone()
newproject.Params = RaycastParams.new()
newproject.Params.FilterType = Enum.RaycastFilterType.Exclude
newproject.Params.FilterDescendantsInstances = {whitelist, clo}
function newproject:Cast (start, dest, force)
local conversion = 196.2/9.8
local vforce = (dest - start).Unit * force * conversion
local a = Vector3.new(self.Wind.X,self.Wind.Y - self.Gravity * 9.8,self.Wind.Z) * conversion
local t = 0
local currentpos = start
local rayresult = nil
local found = false
clo.CFrame = CFrame.new(start)
if not self.Visualize then
clo:Destroy()
end
local connection = run.Heartbeat:Connect(function(dt)
if not found then
t += dt
local projpos = Vector3.new(
start.X + vforce.X * t + 0.5 * a.X * t * t,
start.Y + vforce.Y * t + 0.5 * a.Y * t * t,
start.Z + vforce.Z * t + 0.5 * a.Z * t * t
)
rayresult = workspace:Raycast(currentpos, projpos - currentpos, self.Params)
currentpos = projpos
if self.Visualize then
clo.Position = projpos
clo.Anchored = true
clo.CanCollide = false
clo.CanTouch = false
clo.Parent = workspace.effects
local cframe = CFrame.lookAt(projpos, projpos + dest)
clo.CFrame = cframe
print(clo.Orientation)
end
if rayresult or t > self.DespawnTime then
found = true
end
end
end)
while not found do
wait()
end
connection:Disconnect()
if rayresult then
print("detected")
local part = Instance.new("Part")
part.Size = Vector3.new(5,5,5)
part.Position = rayresult.Position
part.Anchored = true
part.CanCollide = false
part.Material = Enum.Material.Neon
part.Color = Color3.new(1,0,0)
part.Shape = "Ball"
part.Parent = workspace.effects
debris:AddItem(part,0.5)
local block = rayresult.Instance
print(block.Name)
end
end
return newproject
end
return projectile