Raycast Hitbox 4.01: For all your melee needs!

I get this error when unequipping the tool when in the middle of a swing, it results in the tool being permanently broken, any fixes?
image

2 Likes

The math for the attachment solver appears to be wrong:

What this is doing is making the ray:
Origin: currentPosition
Direction: currentPosition - lastPosition
Endpoint: currentPosition + (currentPosition - lastPosition)

This makes the ray inaccurately go into things it hasn’t reached yet, or even into things it will never reach, the desired outcome should be going from current to last

Which would be:
Origin: currentPosition
Direction: lastPosition - currentPosition
Endpoint: lastPosition

Even with the corrected math, in my opinion going from current to last is unexpected behavior as I would assume the rays to travel in the direction of movement, last to current.
Which would be
Origin: lastPosition
Direction: currentPosition - lastPosition
Endpoint: currentPosition

1 Like

hello!

i am using this module for my lightsabergame and now i want to add blocking!

(!BTW RAYCASTING IS PRETTY NEW FOR ME!)

i dont know what i need to do to make the blocking work but i want to make it so when a value in a tool is true blocking will be enabled and the raycasthitbox does no dmg to the player with the blocking value… here is the serversided code i used for the attacks

local remoteEvent = script.Parent.Parent.AttackFolder.Attack1
local tool = script.Parent.Parent
local plr = tool.Parent.Parent
local char = plr.Character
local m1 = script.Parent.Parent.Handle.Hit
local Damage = script.Parent.Parent.dmgfolder.dmg.Value
local RaycastHitbox = require(game.ServerScriptService.RaycastHitboxV4)
local Hitbox = RaycastHitbox.new(script.Parent.Parent["Lightsaber top"].Part)
hitted = false
blockhitted = false

remoteEvent.OnServerEvent:Connect(function()
	Hitbox:HitStart()
	local Attack = script.Parent.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Parent.Anims.Attack1)
	print("Server Attack1!")
	Hitbox.OnHit:Connect(function(hit, humanoid)
		if hitted then return end
		hitted = true
		if humanoid.Parent ~= char then
			humanoid:TakeDamage(Damage)
			m1:Play()
			print(hit.Name)
			humanoid:LoadAnimation(script.Parent.Parent.Anims.Hit) -- does not work i cant locate the humanoid i hit
		end
		hitted = false
	end)
	Attack:Play()
	wait(0.3)
	Hitbox:HitStop()
	end)

wait(2)
m1:Stop()

and here is the blockedvalue i would like to get detected (In the tool)
image

thanks for helping i will try some solutions myself too.

Does this module work for Classic Swordfighting type Swords?

1 Like

It should. The example place on the post has exactly that.

This is extremely useful. I’ll definitely be implementing this into my combat game!

For one of my games i have a script in serverscriptservice that adds the attribute ā€œCanBlockā€ to your humanoid, this is what the code looks like

game.Players.PlayerAdded:Connect(function(Player)
	
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:FindFirstChild("Humanoid")
		if Humanoid ~= nil then	
			Humanoid:SetAttribute("Blocking", false)	
			Humanoid:SetAttribute("CanParry", false)
		end	
	end)	
end)

For a simple blocking mechanic you could check if blocking is true upon hitting the enemy, that would look something like:

local CheckBlock = enemyhumanoid:GetAttribute("Blocking")

if CheckBlock == true then
     --code here depending on what you want to do when they hit a block
end

1 Like

Hey there, I’m curious if the raycast hitbox module will get another update, since Roblox recently released some new API, the Shapecasts, from here:

Would be really cool if the raycast hitbox could potentially handle shape casts too

6 Likes

Are you going to change the code for this module with the new release of shapecasts??

2 Likes

I’d appreciate it if anyone can help me with using this module,

1 Like

I’m having issues with this. I’m not sure if I am doing something wrong but if I stand still and hit the same character it stops detecting the hits unless I move prior to hitting it.

local handle = script.Parent
local tool = handle.Parent

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RaycastHitbox = require(ReplicatedStorage.RaycastHitboxV4)

local newHitbox = RaycastHitbox.new(script.Parent)
local Params = RaycastParams.new()

local hitSound = handle:WaitForChild("Hit")
local swingSound = handle:WaitForChild("Swing")


local charDefined = false

tool.Equipped:Connect(function()
	if not charDefined then
		charDefined = true
		Params.FilterDescendantsInstances = {tool.Parent}
		Params.FilterType = Enum.RaycastFilterType.Exclude
		newHitbox.RaycastParams = Params
		
	end
end)


local deboucne = false
local turnOffAfterThisAmountOfSeconds = .25

tool.Activated:Connect(function()
	if deboucne == false then
		deboucne = true
		swingSound:Play()
		newHitbox:HitStart(turnOffAfterThisAmountOfSeconds)
		tool.Grip = CFrame.new(Vector3.new(0, 0, -1.25)) * CFrame.Angles(math.rad(180),0,0)
		task.wait(0.75)
		tool.Grip = CFrame.new(Vector3.new(0, 0, -1.25)) * CFrame.Angles(math.rad(90),0,0)
		task.wait(.25)
		deboucne = false
	end
	
end)


newHitbox.OnHit:Connect(function(hit, humanoid)
	hitSound:Play()
	print(hit)
	humanoid:TakeDamage(1)
end)

robloxapp-20230618-2254499.wmv (1.9 MB)

1 Like

wait so we cant fire events in the hit event?

1 Like

I believe the rays would require a non-zero direction vector. Not moving means the displacement is 0 and that means the direction vector’s magnitude is 0, meaning the direction vector is itself a zero vector.

I think this is what is causing you the issues.

@fembussing @IntentionalChaos

I implemented Shapecasts in this module. I have messaged @TeamSwordphin about my Pull Request. You could, however, get the source directly and use it from here:
GitHub - OptimizedFunction/raycastHitboxRbxl: Requires Roblox Studio and knowledge of its API - Free to use for everybody

Original work is by @TeamSwordphin, I have only implemented support for Shapecasts.

Changes Made:

Expand

Hitbox.new()

Hitbox.new() now takes two arguments:

  • object: any?
  • ShapecastMode: ShapecastModeEnum?

ShapecastMode defaults to Line if not provided.

ShapecastModeEnum

Line

  • Uses the classic Raycast method.
  • Casts a single line.

Sphere

  • Uses the SphereCast method.
  • Casts a circle.
  • Hitbox.SphereCastRadius is used to set the radius for the SphereCast.

Block

  • Uses the BlockCast method
  • Casts a cuboid.
  • Hitbox.BlockCastSize is used to set the radius for the BlockCast.

New Properties:

Hitbox.SphereCastRadius: number

  • This property defines the radius of the sphere to cast when ShapecastMode is set to Sphere

Hitbox.BlockCastSize: Vector3

  • This property defines the size of the cuboid to cast when ShapecastMode is set to Block
10 Likes

Yo Can I Like Use This For Projectiles?

The FastCastModule in question:

Well, you could. But for projectiles, I would suggest using FastCast. It has a lot more features and is specifically for projectiles.

FastCast is better suited for projectiles, but this one is for melee weapons as the title says ā€œFor all your melee needs!ā€, while FastCast on the other hand, it says this in the title ā€œMaking a combat game with ranged weapons?ā€

I want to make damage depend on the attackers stats. I’m having a problem sending and receiving my own tables. So how could I do this?

Off-Topic but I dont think the creator is gonna update this. I checked his profile and it says ā€œOut of devforum due to life stuff.ā€ But he’s probably gonna be active more, so who knows?
Anyways, I dont use this anymore. I’m currently using a ā€œBoundingBoxā€ method to do this. This module is limited. And yes, I still use ā€œBlacklistā€ and ā€œWhitelistā€. I just get the new ones mixed up.
But this causes some lag now.
I hope someone remakes this module!