How to make a certain sized hitbox or different shape of hitbox

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make different size of hitbox or shape hitbox like a cone shape hitbox or a rectangle shape hitbox in front of the player, or a hitbox that covers the whole character but has a very high length. So basically I want to create a hitbox with different type of z x and y axis. This is for a attack skill.

  2. What is the issue? Include screenshots / videos if possible!
    I mean something like All star tower defense
    image
    image

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried using raycast, but it just a beam and it only increases in distance length and can’t increase it’s vertical length or increase width. I did use that raycast forum but that is creating many lines of attachment on a part, so I was trying to find a better method. I tried using magnitude but it increases as a spherical region size and so I can’t specifically change z,x or y axis differently, I tried seeing the dot function of it but I want to increase the vertical size more of it while the x axis size stays the same. I was thinking of using region3 but many people say it is bad performance and isn’t very good to use, and I don’t want to just create a part every time to check for a hitbox.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

2 Likes

Try reading this it may help:

Please mark this as solution if this helped

This wouldn’t help at all, He wants towers to only attack directly in front of them, there is a math thing that allows this!

First of all we would want the lookvector of the tower and the direction to the currently targeted enemy (every time you shoot you should be testing all enemies for this criteria)

The lookvector is pretty easy to get, just yoink it from the tower’s primary part

local LookVect = Tower.PrimaryPart.CFrame.LookVector

The direction is a bit harder to get but it is still very simple

local Dir = (Enemy.PrimaryPart.Position - Tower.PrimaryPart.Position).Unit

Why does the above work? The answer is very straight forward, the formula for vector direction is
Endpoint - Startpoint
Doing this gets the amount that you need to travel from startpoint to endpoint
We also make it a Unit vector which just shortens the direction down to just one stud
image
Now we just need to check the difference between them

We can do this by getting their dot products

local Dot = LookVect:Dot(Dir)

The dot product would return a value between 1 and -1, 1 is if they are in the same direction, -1 is if they are exact opposites, and 0 would be if they were perpendicular, in the case above the dot product would be about 0.5, You can use this just raw OR you could calculate it into degrees

local Degrees = math.deg(math.acos(Dot))

The reason that above works is because the Dot is the cosine of the angle, to get the actual angle we want to use math.acos(), Then math.acos returns the angle in Radians which are 0-~3.14 instead of 0-360, math.deg returns the degree counterpart of a radian.
(Testing the code with the example above we get about 45 degrees)

From here we can just test if the Degrees are lower than an angle cutoff and the Direction’s magnitude is less than the range of the tower

1 Like

thank you very much, and sorry for the late reply.