Problem with shapecast giving error

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!
    Seem like this error is crashing my game, it only appears like a few minutes after I execute the game, I really dont know what can cause the issue

  2. What is the issue? Include screenshots / videos if possible!

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Yes I did but found nothing with this specific problem

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!

this is the code part that is calling the function:

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Can you send a screenshot with the lines on the left shown?

I think its the line that shapecasts, and is put into the variable hitBox.

If you do projPos - currentPos, there is a chance that it will exceed greater direction than the 1024 limit.

So you need to clamp the direction on all values to not exceed 1024.

Your problem is on that hitBox definition line, on the 3rd parameter in the spherecast.

1 Like

should i do this?

math.clamp(Projpos-currentPos , 0,1024)

Direction is a vector, and math.clamp() only works on numbers. You can do this for line 90.

local hitBox = WorkSpace:Spherecast(currentPos, 2 (projPos - currentPos).Unit * 1023, self.Params)

.Unit() returns the normalized vector, which is 1’s and 0’s. So then you can multiply it by the desired length, in this case 1023 studs.

1 Like

I think the issue seen is that Spherecast’s parameters is getting something larger than 1024, which of course is making errors. (Don’t know what the crashes are from)

According to Spherecast’s documentation, the distance is taken from the third argument, which is also used as a direction for some reason?
So as a compromise, you could do something like this:

local sphereDirection = (projPos - currentPos).Unit * 1024
local hitBox = WorkSpace:Spherecast(currentPos, 2, sphereDirection, self.Params)
1 Like

Thanks @LxckyDev and @Dragon_Trance will try it and let you know if it is fixed thanks guys

It worked smoothly, thanks!! :smiley:

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