R6 hitboxes on R15 characters

#1

Some people don’t like the hit boxes on the R15 avatar because it has too many parts, and don’t use it in swordfighting games because of it. At the same time, it also does look better.

I made this in about an hour to show how the hit boxes for R6 avatars might be put onto an R15 avatar, so you can have the nice animations that come with R15 while still being able to use legacy linked sword scripts. The place below is opensource, and steps below instruct on the creation of this place.

The main script is called “R6HitboxScript”. It welds the R6 avatar to the R15 one, and sets up collision groups so that the R6 avatar will not be detected by other scripts. Inside is a model, with all the parts of an R6 avatar, which have been made red and transparent so that you might watch how it functions. In an actual implementation, the R6 avatar probably wouldn’t be visible.
The parts are also mass-less so that they do not slow down shift-lock - I noticed a drag from the mass when you try to rotate if the parts are not mass-less.

A copy of the ROBLOX R6 Animator is inside the R6 avatar, which has been modified slightly so that the R6 model will animate using the R15 humanoids animator. It also detects tools in the R15 model instead of the R6 one, and will not destroy the “animStringValueObject” or you will get a bug where the animator scripts do not always both see the tool swings.

The R15 animator has been changed to wait slightly before deleting the “animStringValueObject” because there needs to be time for the R6 animator to see it.
With the above animation scripts, your hit-boxes are setup.

I used and modified this sword script while creating this place:

In the sword script, I disabled R15 animations because it is easier to setup this way, however you could animate a custom rig with both character models so that the sword swings are in sync.
To disable the R15 animations in the sword script, I commented out the lines shown commented here:

--if Humanoid.RigType == Enum.HumanoidRigType.R6 then
			local Anim = Instance.new("StringValue")
			Anim.Name = "toolanim"
			Anim.Value = "Slash"
			Anim.Parent = Tool
		--[[elseif Humanoid.RigType == Enum.HumanoidRigType.R15 then
			local Anim = Tool:FindFirstChild("R15Slash")
			if Anim then
				local Track = Humanoid:LoadAnimation(Anim)
				Track:Play(0)
			end
		end]]

These are in the “Attack” function in the script “SwordScript” in the sword tool.

Next, I created this “FindCharacter” function and put it before the “Blow” function in the same script.

function FindCharacter(hit)
	if hit.Parent and hit.Parent.Name == "R6Hitbox" then
		if hit.Parent.Parent and hit.Parent.Parent.Parent then
			return hit.Parent.Parent.Parent
		end
	end
end

It detects hits against the R6 character model, and targets the R15 humanoid. It will ignore all other hits.
Normally, the sword script finds the hit character using this line here:

local character = Hit.Parent

You need to make a small change so instead the “FindCharacter” function is used:

local character = FindCharacter(Hit)

Now the final step in setting up this sword to work with our hit-boxes is to set the collision group of the handle. The code below creates any collision groups which are needed, and makes the handle collide with the hit-boxes. It can be pasted at the end of the sword script.

local physicsservice = game:GetService("PhysicsService")
do
	local doesExist = pcall(function()
		physicsservice:GetCollisionGroupId("absolutelynocollisions")
	end)
	if not doesExist then
		physicsservice:CreateCollisionGroup("absolutelynocollisions")
		physicsservice:CollisionGroupSetCollidable("Default","absolutelynocollisions",false)
	end
end
do
	local doesExist = pcall(function()
		physicsservice:GetCollisionGroupId("swordHandles")
	end)
	if not doesExist then
		physicsservice:CreateCollisionGroup("swordHandles")
		physicsservice:CollisionGroupSetCollidable("swordHandles","absolutelynocollisions",true)
	end
end
physicsservice:SetPartCollisionGroup(Handle,"swordHandles")

An issue I see with a system like this is, what you see is not actually representative of where you should hit, so maybe there should be something to make the hit boxes visualise when you have a sword equipped, or are fighting someone. It might be cool to link the transparency to the players health.

5 Likes
closed #2

This topic was automatically closed after 1 minute. New replies are no longer allowed.

opened #3