Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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

0
Add in print(tostring(main.CFrame.LookVector * (hit.Position - main.Position).Magnitude)) on line 24 and tell me what you get mc3334 649 — 5y
0
It doesn't print anythign ..? Denzel2415 -4 — 5y

1 answer

Log in to vote
0
Answered by
mc3334 649 Moderation Voter
5 years ago

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.

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 Denzel2415 -4 — 5y
0
ahhh I see now mc3334 649 — 5y
Ad

Answer this question