How to make a jump attack?

I am currently trying to make a fighting game, here is my problem, I want to make a jump attack skill. I have tried different method, including animation + Linear velocity, keep set the character position, use alignPosition, use BodyPosition, but I think the result is not I want. I want to ask are there any better method for making a jump attack, when jump attack, I want the HRP to jump together(not only the character jump with animation and HRP move horizontally).

I want it can has a fixed end point, for example, the jump attack move the character front for 80 studs, and each time need to move for 80 studs (sorry for not clear)

The jump attack is jump front with a curve line

I will be happy for any help, thank you.

2 Likes

you could set the hrp’s assemblylinearvelocity instead of finicking with constraints and movers
example: HumanoidRootPart.AssemblyLinearVelocity = HumanoidRootPart.AssemblyLinearVelocity + Vector3.yAxis*JumpForce

2 Likes

But this only provide a upper force, I want to front & upper force, can it still work smoothly if use AssemblyLinearVelocity ?

Personally, I prefer using BasePart:ApplyImpulse rather than setting its AssemblyLinearVelocity for jumping, which you can do like so:

local FrontAndUp = Vector3.new(0, 1, -1)
local JumpForce = 500

HumanoidRootPart:ApplyImpulse(CFrame.lookAlong(HumanoidRootPart.Position, FrontAndUp).LookVector * JumpForce)

Are you trying to make the attack jump on activation or only be able to use the attack while jumping? There is a Jump method on Humanoids and you could also use the Humanoid’s state machine to see when the character is jumping or falling (if you wanted to count that).

1 Like

sorry for not clear, but I want it can has a fixed end point, for example, the jump attack move the character front for 80 studs, and each time need to move for 80 studs, so I am afraid of any forceApply cannot work, or maybe there are some methods that I don’t know how to do

I want to make it on activation

I would use lookvector of humanoidRootPart with humanoidRootPart’s already existing velocity + y axis velocity push.

Pseudo-code for lookVector

--Pseudo-code
local jumpPower = 10

local function jumpAttack()
	local rootPartLookVector = rootPart.CFrame.LookVector
	local desiredYVelocity = Vector3.yAxis * jumpPower

	rootPart.Velocity *= rootPartLookVector + desiredYVelocity
end

jumpAttack()
1 Like

But can this make a fix end position of the jump point?

You need to properly set your multiplication because you can configure strength of the velocity.
From your post I understood that you want to jump different distances? Just do that by multiplying horizontal velocity or vertical.

1 Like

This should work:

local JumpDistance = 80 -- In studs

local JumpHeight = 10 -- Also in studs

local JumpTime = 1 -- In seconds. How long the jump will take

local KeyInterpolationMode = Enum.KeyInterpolationMode.Linear -- Feel free to experiment with changing this

JumpTime = 1 / JumpTime -- This is so we can multiply the delta instead of divide, which will improve performance

local function jumpAttack(character: Model)
	local pivot = character:GetPivot()
	local half = pivot:PointToWorldSpace(Vector3.new(0, JumpHeight, -(JumpDistance / 2)))
	local done = pivot:PointToWorldSpace(-(Vector3.zAxis * JumpDistance))

	local curve = Instance.new("Vector3Curve")
	curve:X():SetKeys{
		FloatCurveKey.new(0, pivot.X, KeyInterpolationMode),
		FloatCurveKey.new(0.5, half.X, KeyInterpolationMode),
		FloatCurveKey.new(1, done.X, KeyInterpolationMode)}
	curve:Y():SetKeys{
		FloatCurveKey.new(0, pivot.Y, KeyInterpolationMode),
		FloatCurveKey.new(0.5, half.Y, KeyInterpolationMode),
		FloatCurveKey.new(1, done.Y, KeyInterpolationMode)}
	curve:Z():SetKeys{
		FloatCurveKey.new(0, pivot.Z, KeyInterpolationMode),
		FloatCurveKey.new(0.5, half.Z, KeyInterpolationMode),
		FloatCurveKey.new(1, done.Z, KeyInterpolationMode)}

	local x = 0

	repeat
		x = math.min(x + (JumpTime * task.wait()), 1) -- Increment 'x' using the delta time returned by "task.wait"

		local position = curve:GetValueAtTime(x) -- "GetValueAtTime" returns an array...
		position = Vector3.new(position[1], position[2], position[3]) -- ...so we'll need to convert it to a Vector3

		character:MoveTo(position)
	until x == 1
end

I recommend calling the function using task.spawn, like so:

task.spawn(jumpAttack, Character)

This will prevent any issues from popping up in the future with the repeat until loop blocking any code written below where you’ve called the function from running :slight_smile::+1:

It will also make cancelling the jump much easier, since you can use task.cancel on the thread returned by task.spawn


@GGreenBBoy123 I’ve managed to make a simpler version that uses AlignPosition:

local JumpDistance = 80 -- In studs

local JumpHeight = 10 -- Also in studs

local AlignPosition = Instance.new("AlignPosition")
AlignPosition.Mode = Enum.PositionAlignmentMode.OneAttachment
AlignPosition.ApplyAtCenterOfMass = true
AlignPosition.MaxForce = math.huge
AlignPosition.MaxVelocity = 40 -- Change this value to edit how long the jump takes

local function jumpAttack(Character: Model)
	local PrimaryPart = Character.PrimaryPart or Character:WaitForChild("HumanoidRootPart"):: BasePart

	local Half = PrimaryPart.CFrame:PointToWorldSpace(Vector3.new(0, JumpHeight, -(JumpDistance / 2)))
	local Done = PrimaryPart.CFrame:PointToWorldSpace(-(Vector3.zAxis * JumpDistance))

	local AlignPosition = Instance.fromExisting(AlignPosition)
	AlignPosition.Position = Half
	AlignPosition.Attachment0 = PrimaryPart:WaitForChild("RootAttachment")
	AlignPosition.Parent = Character

	repeat task.wait() until (PrimaryPart.Position - Half).Magnitude < 0.5

	AlignPosition.Position = Done

	repeat task.wait() until (PrimaryPart.Position - Done).Magnitude < 0.5

	AlignPosition:Destroy()
end

It seems to be more stable than the previous version, and I’d also recommend calling this function using task.spawn due to the repeat until loops

You can also stop the jump by cancelling the thread, but you’ll also need to destroy the AlignPosition in this version, otherwise the player’s character will be stuck floating in the air :smile:

Do make sure to destroy the AlignPosition that’s parented to the player’s character though, not the AlignPosition being used as a template

1 Like

ok, thank you so much, I am first time see Vector3Curve, let me have a try and learn, thank you!

1 Like