Battlegrounds game combat system

Me and my friend want to make a battlegrounds game.
We already have a combat system and character selection BUT the combat script i wrote uses raycasting, is there a better alternative? because i didnt make a custom hitbox (kinda) and u have to aim more accurately for you to land your hits.

we talked about .touched and all that but were afraid for ping issues etc.
and also whats a better way to block attacks from only the front (the way i did it is basically in a way making the person immortal while blocking)

1 Like

I’d say workspace: GetPartBoundsInRadius is one of the fastest and cheapest ways to detect “collisions” for things like punching etc.

Alt. GetPartsInPart incase your BoundingBox is significantly bigger than your character. (Which happens if you parent your projectiles into your character).

2 Likes

thats a first time i hear about it.
is GetPartBoundsInRadius something that is already a “hitbox” itself or do i have to make that myself, like i get a part put it in character etc etc?

1 Like

you have to manually trigger the GetPartsInX() method everytime you want to check if something is there sadly.

1 Like

To detect blocking from the front, you could use

local x = YourLookVector:Dot(otherLookVector) -- returns num from -1 to 1
-- Returns 1 if vectors aren't facing each other
-- Returns -1 if vectors are facing each other

which detects if the players whether two look vectors are facing each other

I personally use:

local angle = math.acos(enemyHrp.CFrame.LookVector:Dot((enemyHrp.Position - myHrp.Position).Unit))
-- If angle is greater than 0.5, then they are looking at each other
-- 0.5 to 1.0 is how closely the two are facing each other

When I want to assign damage (or do whatever else) based on how closely they are looking at each other

3 Likes

It’s a function that returns all parts within a radius of a position, but it simplifies the rotation of the part into a boundingbox which is basically the same.

Speed it up further but adding a single part in each player with the collisiongroup “Hitbox”, then set overlapParams.Collisiongroup = “Hitbox”

ooooh, thank you! thats actually sm easier then raycast :sob:

I already figured out how to do the blocking from the front. since i made it that your character is always facing where your camera is

		local directionToAttacker = (attackerRoot.Position - targetRoot.Position).Unit
		local facingDirection = targetRoot.CFrame.LookVector
		local dot = facingDirection:Dot(directionToAttacker)
		if dot > 0.5 then
			return
		end
	end```

yeah i had some troubles trying to get it to work before i figured that out :sob:

1 Like