The Basics of Combat Games: Hitboxes

Hi, do you have examples of projectiles, specifically in a .rbxl to check out?

Thanks

2 Likes

I don’t have access to roblox studio right now, but the process should look something like this:

  • Server fires to client with data on which projectile to make.
  • Client creates projectile, and then replicates this to the server and then all other clients (We won’t have the proper direction to give to the other clients until the projectile is made, so we do it here.)
  • The projectile can be moved in a variety of ways, such as moving it with RenderStepped, using physics constraints, ect.
1 Like

Waiting for the third part of this awesome guide!!

2 Likes

I recommend choosing between raycast/magnitude. Spatial query methods such as getpartsinboundsbox can be a bit costly.

1 Like

There are quite a few cases where spatial query is a better fit than raycast and magnitude, such as ground-level attacks that can be jumped over, or a tall and thin hitbox. Neither raycast nor magnitude could effectively provide that without having to write a whole new function.

1 Like

Edit: Added new section for ‘Early Attack Signaling’

sorry if I’m late, but i got a question.
In the Part of RayCast Hitboxes, there’s the parameter Attachments, and then it is used and looped trought. though i don’t understand what should be passed when called the function (Yeah its some attachments but i don’t understand what their position has to be ec…). Thanks in advice and Nice tutorial : )

I love it but something i immediately noticed is comments being started with --//letter, its kinda hard to read, i get it’s probably a style or plugin or something but it was kinda annoying to read (you get used to it over time) you can probably add a space after the // (–// letter) or just use a normal comment (-- letter) not judging you just a nitpick i had reading, i’m gonna read the rest now

should

be OnServerEvent? just confused as it’s a server script

good job on the tutorial btw its already very high quality, i’ve had it bookmarked for a while and just got to reading it

The position of the attachments should be along whatever the base of the attack is. For example, if you have a sword, you should have the attachments along the blade.

You’re correct about the Event connection, it should be OnServerEvent.I’ll edit the post to fix that.

1 Like

Oh alright, Thank you ! :slight_smile: Very nice tutorial.

pardon me if im dumb but i cant test right now and its kinda been bothering me a little, wouldnt this always be over os.clock? how will this line work, my brain might be malfunctioning again

os.clock() will keep bringing newer and newer times, eventually surpassing the first benchmark.

1 Like

Oh, thank you, I see! I got time to test and tested using this code to understand it better.

local StartTime = os.clock()

while (StartTime + 5 > os.clock()) do
	task.wait(0.05)
end

print("finished in", os.clock() - StartTime)

DetectionInfo.Time is how long the attack/hitbox lasts, correct?

That’s correct.

keystrokes keystrokes

1 Like

wouldn’t you want to update the attachment every 0.1 (checkInterval) seconds rather than everytime it recieves a result? Pardon if I’m wrong here.

Hi, you said in your post that we should check the distance of the players hit on the server to prevent cheaters from passing wrong info on the server. But the problem is there’s a difference between what the player sees and what the server sees due to latency so even if the player was close enough to hit the player on his view the server would still ignore the request. One partial solution is to have a big margin of the minimum distance that the player should be in range but if we had a game where different player have different speeds then this approach is also flawed since a very fast player will have bigger delay than a slow player. Any solution to this problem ?

Woops, that should be outside of the hit detection. I’ll correct that.

1 Like

You’d only have to worry about that in games where characters go at speeds higher than 40 studs /per second, but even then, you can just increase the leniency for and against the player moving at a high speed, and set it back to normal when they aren’t moving quickly.

Here after firing the client, there should be a task.wait(DelayTime) OR add a + DelayTime to the while loop pre disconneection so it doesn’t disconnect the function before the hitbox has a chance to be made (I BELIEVE)

This < should be an >

Also some variables are global, when they should be local, i know it’s just an example and it doesn’t matter but it still triggers me for some reason, no hate, just some mistakes I found

1 Like