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?
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.
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.
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?