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

umm can someone explain this to me? im learning to make fps game but i dont undestand [ANSWERED]

Asked by 4 years ago
Edited 4 years ago
local replicatedstorage = game:GetService("ReplicatedStorage")
local remoteevent = replicatedstorage:WaitForChild("ShotEvent")

remoteevent.OnServerEvent:Connect(function(player, gunpos, moupos)
    local bullet = Instance.new("Part")
    bullet.Name = "Bullet"
    bullet.Parent = game.Workspace
    bullet.Position = gunpos
    local distance = (moupos - gunpos).magnitude
    local speed = 500
    bullet.CFrame = CFrame.new(gunpos, moupos)
    bullet.Velocity = bullet.CFrame.lookVector * speed
end)

up there is code but i understand everything except this part(i understand "local speed = 500")

    local distance = (moupos - gunpos).magnitude
    local speed = 500
    bullet.CFrame = CFrame.new(gunpos, moupos)
    bullet.Velocity = bullet.CFrame.lookVector * speed
0
assuming the parameter moupos is mouse position and gunpos is the gun position, .Magnitude converts 2 positions into a number (aka distance away from each other), bullet.CFrame on line 3 sets the position of the bullet to the gun while the rotation is towards the mouse, the bullet then shoots on line 4, shoots in the direction at a certain speed. greatneil80 2647 — 4y
0
thank you, and how can i mark you as solution? Sabailuridze 126 — 4y
0
You can only mark answers as solutions, you can add [ANSWERED] to the title Leamir 3138 — 4y
0
ok thanks Sabailuridze 126 — 4y

Answer this question