My double jump is sometimes making the player jump downwards instead of upwards

Hi, So I’m making a double jump system but the player sometimes moves forwards when the body velocity is applied. However, it also sometimes goes the correct way and shoots up. Can someone help?

-- Part of the code, the bodyV does get destroyed 0.15 seconds after 
local bodyV = Instance.new("BodyVelocity")
		bodyV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		bodyV.Velocity = CFrame.Angles(math.rad(50),0,0) * character.PrimaryPart.CFrame.lookVector * (100 + addedJumpPower)
		bodyV.P = 3000000
		bodyV.Parent = character.PrimaryPart
		anim:Play()

Could we see what is hapenning here?

I can send a video hang on
(hhh)

Hello, this is a double jump script I made a while ago and may be worth giving a try:

local jumps = 1 -- number of double jumps (0=single jump,1=double jump,2=triple jump etc)
local jumped = 0

game:GetService("UserInputService").JumpRequest:connect(function()
	if jumped < jumps + 1 and jumped > 0 then
		game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Velocity =
			Vector3.new(game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Velocity.X,
				game:GetService("Players").LocalPlayer.Character.Humanoid.JumpPower,
				game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Velocity.Z) -- simulates a jump
	end
	jumped = jumped + 1 -- counts number of jumps
end)

game:GetService("Players").LocalPlayer.Character.Humanoid:GetPropertyChangedSignal("FloorMaterial"):connect(function()
	jumped = 0 -- resets jump count when landed on the ground
end)

As for your code, it appears that you’re going off of the players lookVector, instead you would want to move the player straight vertically.

I meant to say what is the addedJumpPower? Is it a vector?

It is a number

(hhhhhhhhhhhjjjjjjjjj)

Will this just simulate a normal jump? I made a script like this but it makes the player jump higher, not longer. I want it to jump longer as it will be better for the map we have. So more of a 50 degrees angle from the player instead of going straight up.

Here is the video btw:

robloxapp-20210613-0909360.wmv (2.7 MB)

I have modified my code to now include a forward motion variable and a height variable:

local jumps = 1 -- number of double jumps (0=single jump,1=double jump,2=triple jump etc)
local jumped = 0
local addedHeight = game:GetService("Players").LocalPlayer.Character.Humanoid.JumpPower
local addedDistance = 50

game:GetService("UserInputService").JumpRequest:connect(function()
	if jumped < jumps + 1 and jumped > 0 then
		game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Velocity =
			Vector3.new(game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Velocity.X,
				addedHeight,
				game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Velocity.Z) + (game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame.lookVector * addedDistance)
	end
	jumped = jumped + 1 -- counts number of jumps
end)

game:GetService("Players").LocalPlayer.Character.Humanoid:GetPropertyChangedSignal("FloorMaterial"):connect(function()
	jumped = 0 -- resets jump count when landed on the ground
end)

Alright so I see your problem.

This is not how you would calculate a velocity correctly.
Vectors are not rotations rather it is a direction and a length. So to calculate an elevation you need to use math and not CFrame.Angles as using math is much more straighforward.

To get a vector you need a direction and a length or speed.

This is a math for a 50 degree angles vector. Trigonometry

local Speed = 10
local ElevationAngle = 50
local JumpVector = Vector3.new(0,math.sin(math.rad(ElevationAngle)),math,cos(math,rad(ElevationAngle)))) * Speed

This is measured from the Z axis if you want to know. If you want to switch them around you can measure from the Y axis.

How would I apply that to my current script. I tried but it ended up with the character just going forward and not up

Well, I used this and it worked perfectly. Thank you

1 Like