Simulating Hitboxes Server Sided

Hello!

I am working on a little ability, where it will send a wave off and the wave will go into multiple parts - I got all the client sided effects to work perfectly.

I try not to do any effects server-sided for performance, so on the server I went to try and simulate where the particles will be a use that as a way to find out which characters are colliding. I am experiencing a weird issue with the CFrames, when you look in one way it works how its supposed to, but if you look 90* to the left or right the hitboxes are not there.

P.S. I only am making these physical hitbox parts for debugging purposes.

The correct way:

The incorrect way, rotating character 90 degrees and reactivating:

Client Script:

--# ITEMS
	local player, mode, id = details['player'], details['mode'], details['id']
	local characterEffects = EffectManager:get_effects(player)

	--# MODE
	if (mode == 'start') then

		--# ITEMS
		local character = details['character']
		local HumanoidRootPart = character.PrimaryPart or character:FindFirstChild('HumanoidRootPart')

		--# EFFECT
		local atomicWave = characterEffects['wave']:Clone()
		atomicWave.Parent = workspace.Visuals
		atomicWave:SetPrimaryPartCFrame(HumanoidRootPart.CFrame * CFrame.new(0, -3, -8))

		Effects:start_object(atomicWave)

		--# STORE
		Stored[id] = {

			['effect'] = atomicWave,
			['connections'] = {}

		}

	elseif (mode == 'send') then

		--# ITEMS
		local partSpeed = details['speed']

		local atomicWave = Stored[id]['effect']
		assert(atomicWave, 'Atomic Wave does not exist.')

		--# WAVE PARTS
		for _, wavePart in pairs(atomicWave:GetChildren()) do

			--# REPARENT
			wavePart.Parent = workspace.Visuals

			--# ITEMS
			local partVelocity = ((wavePart.CFrame * CFrame.new(0, 0, -2).Position) - wavePart.Position).Unit * partSpeed

			--# VELOCITY
			Stored[id]['connections'][wavePart] = RunService.Heartbeat:Connect(function(deltaTime)

				--# VELOCITY
				wavePart.CFrame +=  partVelocity * deltaTime

			end)

		end

	end

Server:

                        --# CALCULATE
			local startCFrame = HumanoidRootPart.CFrame * CFrame.new(0, -3, -8)
			local targettedCharacters = {}
			local partCFrames = {
				
				[1] = startCFrame,
				[2] = startCFrame + Vector3.new(3, 0, -9),
				[3] = startCFrame + Vector3.new(1, 0, -7),
				[4] = startCFrame + Vector3.new(1, 0, 7),
				[5] = startCFrame + Vector3.new(3, 0, 9),
				
			}
			
			--# VELOCITIES
			for partLabel, startCFrame in pairs(partCFrames) do
				
				--# ITEMS
				local partVelocity =  ((startCFrame * CFrame.new(0, 0, -2).Position) - startCFrame.Position).Unit * 60

				--# VELOCITY
				local timeSinceLastLoop = 0
				
				local partConnection
				partConnection = RunService.Heartbeat:Connect(function(deltaTime)

					--# COOLDOWN
					timeSinceLastLoop += deltaTime
					if (timeSinceLastLoop <= 1 / 20) then return end

					--# VELOCITY
					local partSize = partLabel == 1 and Vector3.new(9, 5, 4) or Vector3.new(4, 5, 4)
					partCFrames[partLabel] = partCFrames[partLabel] + (partVelocity * deltaTime)

					local a = Instance.new('Part', workspace)
					a.Size = partSize
					a.CFrame = partCFrames[partLabel]
					a.Anchored = true
					a.CanCollide = false

				end)
				
			end
1 Like

the “partCFrames” table is there because the parts start off in a model, to move them together, and before the velocity start simulating they become independent parts, so its used to have all their start positions with their offsets from the main part.

From glancing at your code (too long for me to read), you are adding CFrames with Vector3s, which will translate it relative to the world axis, not relative axis.

So instead of adding vectors I should multiple cframes, like so:

[1] = startCFrame,
				[2] = startCFrame * CFrame.new(3, 0, -9),
				[3] = startCFrame * CFrame.new(1, 0, -7),
				[4] = startCFrame * CFrame.new(1, 0, 7),
				[5] = startCFrame * CFrame.new(3, 0, 9),

EDIT: Doing this just made them all into the “incorrect way” that was already shown in my post.

Yes, you should be multiplying CFrames together to get the relative CFrame from startCFrame.

  1. Make sure your CFrame values are correct.
  2. Make sure your visualizer (debug parts) are also synced up and not using the old method.
1 Like

You are very close. To get the relative positions, you can use CFrame’s LookVector and RightVectors to find the positions. Try using these values (I’m not sure if they will work because I haven’t tested in studio but doesn’t hurt to try):

local startCFrame = HumanoidRootPart.CFrame * CFrame.new(0, -3, 0) + HumanoidRootPart.CFrame.LookVector*8
local targettedCharacters = {}
local partCFrames = {
	[1] = startCFrame,
	[2] = startCFrame - startCFrame.LookVector*3 - startCFrame.RightVector*9,
	[3] = startCFrame - startCFrame.LookVector - startCFrame.RightVector*7,
	[4] = startCFrame - startCFrame.LookVector + startCFrame.RightVector*7,
	[5] = startCFrame - startCFrame.LookVector*3 + startCFrame.RightVector*9
}

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