NPC spazzes after attack

Hello people,

I have an issue with the boss that I’m making for my game.
The boss has a “Jump” attack which I have scripted which makes the boss jump from any part of the map at a random player. Now the attack works fine and there isn’t an issue with the attack itself, but after the attack, the boss starts glitching around while walking.

Here is the function which triggers the attack:

local function startJumpAttack(target)
	local playerHumanoid = target:FindFirstChild("Humanoid")
	local playerRoot = target:FindFirstChild("HumanoidRootPart")
	local player = Players:GetPlayerFromCharacter(target)

	if not player or not playerHumanoid or not playerRoot or playerHumanoid.Health <= 0 then return end

	isAttacking = true
	HumanoidRootPart.Anchored = true
	LoadedJump:Play()

	LoadedWalk:Stop()
	LoadedIdle:Stop()

	LoadedJump:GetMarkerReachedSignal("GroundSlam"):Wait()

	HumanoidRootPart.GroundSlam:Play()

	LoadedJump:GetMarkerReachedSignal("Jump"):Wait()

	HumanoidRootPart.Jump:Play()

	local targetPosition = playerRoot.Position + Vector3.new(0, 2, 0)
	local bossStartPosition = HumanoidRootPart.Position

	local jumpHeight = 50
	local midPoint = Vector3.new(
		(bossStartPosition.X + targetPosition.X) / 2,
		math.max(bossStartPosition.Y, targetPosition.Y) + jumpHeight,
		(bossStartPosition.Z + targetPosition.Z) / 2
	)

	local ascendTween = TweenService:Create(HumanoidRootPart, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {
		Position = midPoint
	})
	ascendTween:Play()
	ascendTween.Completed:Wait()

	local descendTween = TweenService:Create(HumanoidRootPart, TweenInfo.new(0.3, Enum.EasingStyle.Sine, Enum.EasingDirection.In), {
		Position = targetPosition
	})
	descendTween:Play()
	descendTween.Completed:Wait()

	HumanoidRootPart.Position = targetPosition

	HumanoidRootPart.GroundLand:Play()

	HumanoidRootPart.Velocity = Vector3.zero
	HumanoidRootPart.RotVelocity = Vector3.zero

	HumanoidRootPart.Anchored = false

	LoadedJump.Stopped:Wait()

	LoadedIdle:Play()

	isAttacking = false
end

And here is the code which handles these attacks and the movement:

local function main()
	HumanoidRootPart:SetNetworkOwner(nil)

	local closestTarget = findClosestTarget()
	if closestTarget == nil then return end

	local playerHumanoid = closestTarget:FindFirstChild("Humanoid")
	local playerRoot = closestTarget:FindFirstChild("HumanoidRootPart")

	if not playerHumanoid and not playerRoot and playerHumanoid.Health <= 0 then return end

	if requiresPathfinding(playerRoot) == true then
		local calculatedPath = CalculatePath(HumanoidRootPart.Position, playerRoot.Position)

		if calculatedPath == nil then return end

		walkPath(calculatedPath, closestTarget)
	else
		Humanoid:MoveTo(playerRoot.Position)
	end

	local distanceToPlayer = ((HumanoidRootPart.Position - Vector3.new(0, 4, 0)) - playerRoot.Position).magnitude
	if distanceToPlayer < 7 then
		startAttack(closestTarget)
	end
	local currentStunAttack = tick()
	if distanceToPlayer > 10 and currentStunAttack - lastStunAttack >= stunAttackDebounce then
		lastStunAttack = currentStunAttack
		startStunAttack()
	end
	local currentJumpAttack = tick()
	if distanceToPlayer > 15 and currentJumpAttack - lastJumpAttack >= jumpAttackDebounce then
		lastJumpAttack = currentJumpAttack

		local chosenPlayer = getRandomLivingPlayer()

		if chosenPlayer ~= nil then
			startJumpAttack(chosenPlayer.Character)
		end
	end
end

Here’s a video, as you can see, the boss keeps slightly teleporting around and the close attack completely breaks the player which doesn’t happen before the jump attack.

Here you can see it glitching horribly:

im willing to bet it has something to do with the tweening and forces acting on the body i.e. grav/velocity

maybe have a runservice loop that sets .y velocity vector to 0, or also set velo and rotvelo to 0 after setting anchored false.

just spitballing

Thanks for your input!

I tried it but it still glitches

Gonna keep the change though because might prevent glitches later.

I forgot to mention that sometimes the boss kinda fuses into the ground like this:

Edit: I hate .wmv

whenver u move a humanoidrootpart of any rig, it glitches the rig, this happens for me all the time when i move a humanoid root part, a ragdoll causing knockback with the power of 50, turns into 9999

set CFrame of the HumanoidRootPart instead of Position, CFrame moves the model and Position only moves the basepart

… same with the other functions that set root’s position

HumanoidRootPart.CFrame = CFrame.new(targetPosition)
1 Like

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