Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My velocity scripts isn't working ? Im using magnitude for the velocity

The script works , it spawns a part but the velocity script isn't working for some reason??

local ray = Ray.new(script.Parent.Position,Vector3.new(0,0,-40))
local Peashooter = script.Parent.Parent
local Damage = 20
local Folder = workspace.Folder
local main = script.Parent
local Debris = game:GetService("Debris")
local plr = game.Players

while wait(2.5)do
	local hit,position = workspace:FindPartOnRayWithIgnoreList(ray,{script.Parent,Folder})
	if hit then 
		
		
		local k = Instance.new("Part", game.workspace)
		k.Anchored = false
		k.CFrame = main.CFrame + Vector3.new(0,0,0)
		k.Size = Vector3.new(1,1,1)
		k.Shape = "Ball"
		k.BrickColor = BrickColor.new("Bright green")
		k.Material = "Neon"
		k.Parent = Folder
		k.CanCollide = false
		
	
		k.Velocity = main.CFrame.LookVector * (hit.Position - main.Position).Magnitude

Debris:AddItem(k,5.5)

 k.Touched:Connect(function(hit)
	local Enemy = hit.Parent.Zombie
   Enemy:TakeDamage(Damage)
k:Destroy()

 end)
	end
	end

2 comments

0

Add in print(tostring(main.CFrame.LookVector * (hit.Position - main.Position).Magnitude)) on line 24 and tell me what you get

0

It doesn't print anythign ..?

1 answer

Line 25 your using .Magnitude. That returns a single number. It is used for finding distance between vector3s. Try replacing .Magnitude with .unit to get the direction vector 3 difference.

2 comments

0

But i want the velocity to be the magnitude distance because I want to make a tower defense game , and Im trying to make something with a projectile which has a trajectory kind of like a mortar

0

ahhh I see now

This discussion is preserved as it was. New answers, comments, and votes are closed.