1
\$\begingroup\$

I am trying to make a projectile (Energy ball) for my game. I am using body velocities, but the issue is is that it seems laggy. I shoot it then half a second through flight it seems to stop in mid air for a quarter of a second then continue. This only happens the first minute of playing.

Here is my code:

local Motion = Instance.new("BodyVelocity", Ball)
Motion.Velocity = ((MouseClickLocation - Player.Character.HumanoidRootPart.Position).Unit*100)

Why is the described behavior happening and how can I make it never happen?

\$\endgroup\$
0
\$\begingroup\$

It is a lot more complicated than that. As the ball travels out far enough away from the player, the network ownership changes from the client to the server. This produces very short, laggy moments. Don't ask me why this happens. All I know is that this can be fixed like this: (I am assuming your using a client activated remote event)

--Where ever you try to put the Motion in, replace that with this
Ball:SetNetworkOwner(Player --[[arg from OnServerEvent]])
RemoteEvent:FireClient(Player, Ball --[[so the client knows what to add the velocity to]])

--In the local script
RemoteEvent.OnClientEvent:Connect(function(Ball)
    local Velocity = Instance.new(BodyVelocity, Ball)
    Velocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    Velocity.Velocity = game.Players.LocalPlayer.Character.PrimaryPart-game.Players.LocalPlayer:GetMouse().Hit.P
end)
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy