hi guys
im working on a baseball game rn, and i use FastCastRedux
to handle pitch and hit balls cuz i know absolutely nothing about physics (I know, laugh at me )
It works pretty good, I have no issue with it whatsoever. The BIGGEST issue i have with it is: I didn’t seem to set it up right, so as the game progresses the game lags more and more. I tried to pin it on the server, but rejoining during the lag seems to fix it, so that leads me to believe its an underlying issue with the client.
The video is of the issue I’m talking about (it usually happens whenever or when someone throws the ball).
Not included because I can’t find it anymore, but video 2 showed a player in the community lagging mid-pitch as soon as the ball was thrown and the lag wouldn’t stop until the cast terminated I believe (although the lag just happens randomly, mostly before a pitch is thrown)
The code snippets below are the ones that run on the client (please ignore how ugly and unorganized it is, im still learning how 2 script )
Here is how I have it set up on the Ball Handler module (which handles ball visuals and partial fielding)
-- // Services \\ --
local PlayerService = game:GetService('Players')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local RunService = game:GetService('RunService')
local DebrisService = game:GetService('Debris')
local ServerScriptService = game:GetService('ServerScriptService')
-- // Variables \\ --
local FastCast = require(ReplicatedStorage.Carnavas.Modules.FastCastRedux)
FastCast.VisualizeCasts = false
local BallEvent = ReplicatedStorage.Carnavas.Events.BallEvent
local CountBindEvent = ReplicatedStorage.Carnavas.Events.CountBindEvent
local BallsFolder = game.Workspace:WaitForChild('Balls', 10)
local GloveSounds = ReplicatedStorage.Carnavas.Sounds.Glove
local Caster = FastCast.new()
local CasterBehavior = FastCast.newBehavior()
Caster.UserData = {}
local HitBall_MarkerCaster = FastCast.new()
local HitBall_MarkerCaster_Behavior = FastCast.newBehavior()
local module = {}
local SZ_Debounce = {false, 3}
LengthChanged
function:
local function OnLengthChanged(ActiveCast, LastPoint, Dir, Length)
local InitialBall = ActiveCast.UserData.InitialBall
local HalfSize = ActiveCast.UserData.InitialBall.Size.Z / 2
local Offset = CFrame.new(0, 0, -(Length - HalfSize))
InitialBall.CFrame = CFrame.lookAt(LastPoint, LastPoint+Dir):ToWorldSpace(Offset)
if Caster.UserData.LandingMarker then
ActiveCast.UserData.LandingMarker = Caster.UserData.LandingMarker
Caster.UserData.LandingMarker = nil
end
if ActiveCast.UserData.LandingMarker then
local LandingMarkerInfo = ActiveCast.UserData.LandingMarker
local LandingMarker = LandingMarkerInfo[1]
local EndPosition = LandingMarkerInfo[2]
if EndPosition and LandingMarker then
local DistanceFromHitPosition = (LastPoint - EndPosition).Magnitude
local FinalSize = math.clamp(ReplicatedStorage.Carnavas.Balls.Baseball.Size.X + 4 * (DistanceFromHitPosition / 25), 2, 28)
LandingMarker.Size = Vector3.new(.75, FinalSize, FinalSize)
end
end
end
Caster.LengthChanged:Connect(OnLengthChanged)
CastTerminating
function
-- CastTerminating function
local function OnCastTerminating(ActiveCast)
local UserData = ActiveCast.UserData
local InitialBall = UserData.InitialBall
if UserData.LandingMarker then
UserData.LandingMarker[1]:Destroy()
end
InitialBall:Destroy()
end
Video: Watch issue_demonstration | Streamable
I am extremely grateful for any help I receive (if I get any but im not really expecting any tbh)