Need help with Hitbox position when turning fast

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

  1. What do you want to achieve? I want the hitbox to stay consistent when turning at highspeeds

  2. What is the issue? When turning and running, the hitbox offset is way too high so the hitbox is far away. a video will be attached.

  3. What solutions have you tried so far? I’ve tried detecting the speed during a turn but its pretty much the same.

	-- Get the killer's current speed for offset
	local humanoid = char:FindFirstChildOfClass("Humanoid")
	local killerHRP = char:FindFirstChild("HumanoidRootPart")

	local sound = game.ReplicatedStorage.SoundFX.Killer.swipe:Clone()
	sound.Parent = killerHRP
	sound:Play()
	game.Debris:AddItem(sound, 2)
	
	local velocity = killerHRP.Velocity
	local actualSpeed = velocity.Magnitude
	print("Speed:", actualSpeed)

	-- Default offset
	local hitboxOffset = CFrame.new(0, 0, -5)

	if actualSpeed > 40 then
		hitboxOffset = CFrame.new(0, 0, -12)
	elseif actualSpeed > 20 then
		hitboxOffset = CFrame.new(0, 0, -8)
	else
		hitboxOffset = CFrame.new(0, 0, -5)
	end
	
	
	-- killer swipe hitbox
	KillerHitbox.Create({
![RPReplay_Final1760850887|video](upload://nLKRBaEG2RUvCBxwcEnD11cEX7R.mov)

		Character = char,
		Mode = "Follow",
		Size = Vector3.new(8, 3, 8),
		Offset = hitboxOffset,
		Duration = 0.2,
		Debug = true,

1 Like

1 Like

I assume you want the relative position to be the same should be something like this

local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local localOffset = CFrame.new(0, 0, -5)

UIS.InputBegan:Connect(function(input, gp)
	if gp or input.UserInputType ~= Enum.UserInputType.MouseButton1 then
		return
	end

	local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart")


	local HitBoxpart = Instance.new("Part")
	HitBoxpart.Size = Vector3.new(8, 3, 8)
	HitBoxpart.Anchored = true
	HitBoxpart.CanCollide = false
	HitBoxpart.Transparency = 0.5
	HitBoxpart.Parent = workspace

	local start = tick()
	local c
	c = RunService.RenderStepped:Connect(function()
		if tick() - start > 3 then
			c:Disconnect()
			HitBoxpart:Destroy()
			return
		end

		local lin = hrp.AssemblyLinearVelocity
		local ang = hrp.AssemblyAngularVelocity

		local predictedPos = hrp.Position + lin * game.Stats.FrameTime
		local mag = ang.Magnitude
		local rotDelta = CFrame.fromAxisAngle(ang.Unit, mag * game.Stats.FrameTime)
		



		local base = hrp.CFrame - hrp.Position
		local predictedCF = CFrame.new(predictedPos) * rotDelta * base

		HitBoxpart.CFrame = predictedCF * localOffset
	end)
end)

2 Likes

thank you i tried something similar and it helped a lot ^^

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