Client-Sided Projectile Visuals

I’m creating a Projectile System that aims to be able to create custom Pathing for Projectiles, but the main issue I’m facing is replicating the custom Path of the Visual Projectile across all clients, as I can’t send the custom Path as a function across a RemoteEvent.

I’m aware I could simply use a ModuleScript to have a library of all the Projectile Paths I can have, without needing to send over the Path function through a RemoteEvent, but it’s a last resort for me personally and I want to achieve this without using Modules for fully customizable Projectile Paths.

Is there anything that I could use to help overcome this?

1 Like

How custom are the paths for each projectile? Do they follow basic physics equations? If so you can replicate to all clients the position, direction, and speed of the projectile from its origin, and then calculate locally on each client the path of the projectile using said physics equations.

Yes, I want to make sure custom paths follow physics formulas.

Would that mean I would use a RemoteEvent every frame to replicate the position of a Moving Projectile for every client?

No just send one remote event each time a projectile is fired, then the client can handle it on their own

Ah, I get it, but goes back to my main question. If one client creates a custom path, how would the other clients receive the info for the said path?

1 Like

Do these projectiles move straight or do they curve

Any type of path, really. My goal is to have one client create a custom path for a projectile, and then have all clients have a visual using that custom path.

Can you give me an example of such paths? Because I believe you could just send a table of data to the client and then the client would handle the rest. You don’t really need a function

I am a bit confused on what you mean, and what these “Custom Paths” are. However you determined the path on one client, you should be able to replicate enough information for all other clients to determine that path themselves locally.

@sonic_848

Perhaps I’m overlooking/overthinking this, but I’ll give an barebones example of how it works.

LocalScript

local Projectile = ProjectileModule.new() -- Created my own Module for Projectiles

Projectile.Path = function(currentCFrame, direction, dt)
  -- Determines the Path of a Projectile over time
  return newCFrame
end

Projectile:Shoot(origin, direction) -- origin: CFrame, direction: Direction

ModuleScript

local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ProjectileVisual = ReplicatedStorage.ProjectileVisual -- RemoteEvent

-- Module Stuff Here

function ProjectileModule:Shoot(origin, direction)
  ProjectileVisual:FireServer() -- What would I send here?
  local changeTime = 0
  local currentCFrame = origin
  RunService.RenderStepped:Connect(function(dt)
    changeTime += dt
    currentCFrame = self.Path(currentCFrame, direction, dt)
    -- Hit Detection happens here
  end)
end

LocalScript for Visuals

local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ProjectileVisual = ReplicatedStorage.ProjectileVisual

ProjectileVisual.OnClientEvent:Connect(function()
  local changeTime = 0
  RunService.RenderStepped:Connect(function(dt)
    changeTime += dt
    -- What info would be here?
    -- Hit Detection Visuals happen here
  end)
end)

I know I can send over the data of the origin and direction, my question is how would I send the Path function over to all the clients?

Why cant you just place this module in replicatestorage and allow clients to use it?

Because the Shoot function requires the Path function, and that Path function is determined by one client

Oh and Clients are able to use this Modules, for creating projectiles.

I’ve decided to put the Path functions into a separate ModuleScript