You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve?
I am using a remote event and making a beam that creates projectile motion when the player aims. -
What is the issue?
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I already checked if the computation on server and its completely fine. I think the issue here is that the CFrame of the attach0 and attach1 acting weird. Took me so many hours and couldn’t find any solution to this.
--// SERVER-SIDE
local t = 0.3;
local function beamProjectile(g, v0, x0, t1)
-- calculate the bezier points
local c = 0.5*0.5*0.5;
local p3 = 0.5*g*t1*t1 + v0*t1 + x0;
local p2 = p3 - (g*t1*t1 + v0*t1)/3;
local p1 = (c*g*t1*t1 + 0.5*v0*t1 + x0 - c*(x0+p3))/(3*c) - p2;
-- the curve sizes
local curve0 = (p1 - x0).magnitude;
local curve1 = (p2 - p3).magnitude;
-- build the world CFrames for the attachments
local b = (x0 - p3).unit;
local r1 = (p1 - x0).unit;
local u1 = r1:Cross(b).unit;
local r2 = (p2 - p3).unit;
local u2 = r2:Cross(b).unit;
b = u1:Cross(r1).unit;
local cf1 = CFrame.new(
x0.x, x0.y, x0.z,
r1.x, u1.x, b.x,
r1.y, u1.y, b.y,
r1.z, u1.z, b.z
)
local cf2 = CFrame.new(
p3.x, p3.y, p3.z,
r2.x, u2.x, b.x,
r2.y, u2.y, b.y,
r2.z, u2.z, b.z
)
return curve0, -curve1, cf1, cf2;
end
local hrp = script.Parent.Parent.Parent.Character:WaitForChild("HumanoidRootPart")
print(hrp)
local ServerRemote = script.Parent.SnowBallRemote
local db = false
ServerRemote.OnServerEvent:Connect(function(player, Camera)
if not Camera then return end
if player.Character:FindFirstChild("Snowball") and db == false then
if Camera == nil and player == nil then return end
local ray = Ray.new(Camera.Origin, Camera.Direction * 300)
local worldyellow = game.Workspace:Raycast(ray.Origin, ray.Direction)
local g = Vector3.new(0, -game.Workspace.Gravity, 0);
local x0 = player.Character:WaitForChild("HumanoidRootPart").CFrame * Vector3.new(1.6, 1, -2)
if worldyellow then
local v0 = (worldyellow.Position - x0 - 0.5 * g *t *t)/t;
--// This is where it gets crazy when the player aims
local curve0, curve1, cf1, cf2 = beamProjectile(g, v0, x0, t);
ServerRemote:FireClient(player, curve0, curve1, cf1, cf2)
end
end
end)
--// Client-Side
local beamer
LocalRemote.OnClientEvent:Connect(function(curve0, curve1, cf1, cf2)
print(curve0)
if cf1 == nil and cf2 == nil then return end
beam.Texture = game.Workspace.Water.Beam.Texture
beam.TextureSpeed = 0
beam.TextureLength = 0.625
beam.LightEmission = 0.75
beam.TextureLength = 1
beam.TextureMode = game.Workspace.Water.Beam.TextureMode.Value
beamer = beam
local terraria = game.Workspace.Terrain
attach0.CFrame = terraria.CFrame:Inverse() * cf1;
attach1.CFrame = terraria.CFrame:Inverse() * cf2;
beamer.CurveSize0 = curve0;
beamer.CurveSize1 = curve1;
end)
Basically I want to make the server handle the projectile motion because I don’t want the exploiters to read the computation. Also if I let the server make the attach0 and attach1’s CFrame it gets delayed.
I want to make it like this: