FastCast Dodgeball System

Im using Fastcast to make a dodgeball throwing system and it works but I want the direction to be the players mouse. How would I do that using the remote events? ```
– server script
local toolball = workspace.Dodgeball
local plrStrength = 100000000000000

local rep = game:GetService(“ReplicatedStorage”)

local ball = rep.Ball

local fastcast = require(rep.Dependencies.FastCastRedux)

local caster = fastcast.new()
local behavior = fastcast.newBehavior()

local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {toolball}

behavior.RaycastParams = params
behavior.Acceleration = Vector3.new(0, -50, 0)
behavior.MaxDistance = plrStrength
behavior.AutoIgnoreContainer = true
behavior.CosmeticBulletTemplate = ball
behavior.CosmeticBulletContainer = workspace.AvailableDodgeballs

local remoteEvent = game.ReplicatedStorage.Throw

caster.LengthChanged:Connect(function(ActiveCast, lastPoint, rayDir, displacement, segmentVelocity, cosmeticBulletObject)

local newPos = lastPoint + (rayDir * displacement)
cosmeticBulletObject.Position = newPos

end)

caster.RayHit:Connect(function(ActiveCast, RaycastResult, segmentVelocity, cosmeticBulletObject)
local explosion = Instance.new(“Explosion”)
explosion.BlastRadius = 40
explosion.Position = RaycastResult.Position
explosion.Parent = workspace

game:GetService("Debris"):AddItem(explosion, 0.2)
cosmeticBulletObject:Destroy()

end)

remoteEvent.OnServerEvent:Connect(function()

local pos = toolball.Handle.CFrame * CFrame.new(0,0,-50)
local direction = (pos.Position - toolball.Handle.Position).Unit

caster:Fire(toolball.Handle.Attachment.WorldPosition,direction, 200, behavior)		

end)


–local script

local remoteEvent = game.ReplicatedStorage.Throw
local tool = script.Parent

local player = game.Players.LocalPlayer
local plrPos = player.Character.HumanoidRootPart.CFrame

tool.Activated:Connect(function()
remoteEvent:FireServer()
end)


Sorry the coding format is messed up idk why its doing that

If you want the ball to land where the mouse is clicking, I’m relatively sure something like this should work (i’ve never worked with fastcast before and therefore cant guarantee anything)

in the client script’s FireServer event, pass in the parameters Player:GetMouse().Hit.p and Character.HumanoidRootPart.CFrame, which would go in the parentheses of FireServer( here )

in the server script, where you receive your remoteevent, you need the parameters MousePos and HRPCF, which would go the the parentheses of OnServerEvent:Connect(function( here )

some code like this assumedly could be used to calculate the velocity for the ball, but I can’t guarentee anything because I dont have any idea how FastCast’s acceleration system works

local Distance = MousePos - HRPCF.Position
local Duration = math.log(1.002 + Distance.Magnitude * .01)
local Velocity = HRPCF:VectorToObjectSpace(Distance / Duration + Vector3.new(0,workspace.Gravity * Duration * .5,0))
Velocity = script.StartCFrame.Value:VectorToWorldSpace(Velocity) --this is your final velocity

I don’t want the ball to land where the player is clicking I just want the ball to fire in the direction of the mouse like a TPS game.

Anyways I figured it out. I changed these lines in the script to local direction = (mousePos - toolball.Handle.Position).Unit AND local mousePos = player:GetMouse().Hit.p

tool.Activated:Connect(function()
mousePos = player:GetMouse().Hit.p
remoteEvent:FireServer(mousePos)
end)

You have to keep updating the players mouse position everytime you fire the event

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.