How i rotate a knife projectile?

  1. What do you want to achieve? make the knife rotate and facing where is the destination

  2. 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)

  3. 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

2 Likes

anyone want to give me a sulution?

You could probably change the projectile’s orientation in a RunService.Heartbeat function.

1 Like

just add a animation that makes it spin?

ima ttry that, but how like with cframe?, or vector3?

quick update here, i solved. i just found a post and i copy a little by and here is the post

i put it out the heartbeat

clo.CFrame = CFrame.new(start, dest) * CFrame.Angles(math.rad(-90), 0, 0)
2 Likes

Either use ApplyAngularVelocity or an AngularVelocity Constraint with an attachment. Just an alternative that MIGHT lag less, and look better (from what I understand.) Also if you solved it, mark the post that solved it as a solution so other people having the same problem can see what helped you.

2 Likes

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