Character Velocity decreased when jumping

I’m currently making my own character controller (which I’m very new at scripting) for my platformer puzzle game which also uses a custom humanoid. I have basic horizontal movement down which uses LineForce for positioning and AlignOrientation for rotation.

I’m working on the jumping for the controller right now and I’ve it came to my attention when testing that whenever the player started jumping, the velocity of the play was decreased. For example if my character’s velocity based on the HumanoidRootPart was 24 on the X axis, after jumping it would’ve decreased back to 3. I’m using VectorForce for jumping as suggested by a friend of mine but it seems to be very choppy and removes the linearity of the movement.

Current Code used for jumping

--Result is a raycast I used in order to find out if player was on the ground
--Angle is the angle of the surface the player is currently on to ensure
--players can't go over slopes that are fairly steep
--PreviousVelocity is just a value that's irrelevant to the situation

if BaseLib.UIS:IsKeyDown(Enum.KeyCode.Space) and result and Angle <= 40 then
	PreviousVelocity = CurrentSpeed
	CharLib.VectorForce.Force = Vector3.new(CurrentSpeed.X,CharLib.Properties.JumpPower,CurrentSpeed.Z)
end
CharLib.VectorForce.Force = CharLib.VectorForce.Force:Lerp(Vector3.new(0,0,0), .15)

Video demonstrating what the problem looks like in game

6 Likes

You’ll probably want to use an old-fashioned BodyVelocity to control the jump, since you can specify the axes upon which forces are applied, meaning that setting BodyVelocity.MaxForce = Vector3.new(0,X,0) would allow you to apply forces along only the Y-axis without impacting horizontal movement.

I know ROBLOX is trying to move away from the old body movers, but a lot of the more granular functionality of the movers just hasn’t made its way over to the new constraints yet.

1 Like

The only reason I’m not using Body Movers is because of the exact reason you said. I’m trying to familiarise myself with the new constraints but if BodyVelocity is going to work then I’ll probably use it. I’ll touch back if it works or not.

1 Like

Yeah, I believe this is causing the issue where the line force is interfering with the jumping force.

Do you know how you are setting the direction of the line force? When you jump the line force might somehow to directed downwards and ruin the jump.

I’m setting the line force towards a part and the direction its going to, is relative to where the camera is looking at

I agree that the LineForce is most likely interfering with the VectorForce.

Ideally, you should be using a VectorForce for movement. However, VectorForces directly affect the acceleration of your character, so it will continually speed up. Instead, we want the character to reach a constant speed and keep that speed. The solution is to simulate a drag force. That way, your VectorForce will bring you to a certain velocity and then stop. So if you’re able to switch your movement to a VectorForce, the jumping will likely not interfere with it.

I can supply some code when I wake up tomorrow because I’ve done this before.

2 Likes

So I should switch my movement from LineForce to VectorForce? As for the continuous build up of the players’ velocity, I also encountered this when using LineForce so I just used math.clamp in order to cap the speed at 24 on the x and z axis. Also supplying the code would really be helpful

Ok what you’re doing is kind of a hack haha. I actually don’t know how LineForces work (and the devhub article was kinda confusing) but a VectorForce should work for your case. I’m boutta sleep so I’ll send it later.

2 Likes

Yeah, any more details on what this part is? the attachment setup between parts.

Are you exactly sure the line force is in the horizontal direction?

I mean line force can work exactly the same as vector force but it’s kinda harder to set the direction as you would need to fiddle with both attachment positions instead of adjusting just one vector force.

Edit: Also your character looks kinda like the Hello World bot lol I would love to see a game based on that.

1 Like

My LineForce setup basically has 2 attachments, one for the HumanoidRootPart and one for a seperate part which I use as the part that determines the direction of where the player is moving to. I basically position the part depending on where the camera is and use the HumanoidRootPart’s position as the base position for the part.

Also yeah the character is based of the Hello World bot, I made a version of this a while back but it was pretty unorganised and buggy lol

Sorry but I’m wondering about this exact detail. Are you constantly changing the position of this part to be horizontal with the HumanoidRootPart’s? any images of this part made visible to debug the direction of the line force?

I’m changing the part’s position based on the characters input and camera’s direction

Video of what it looks like (White neon part is the part used for the LineForce):

Perhaps print out/use the lua debugger to find the vector between attachments. If it’s horizontal then the y value should be zero.

Then try jumping alongside the print debugging it should horizontal along the floor as well.

Sorry I haven’t heard of the Lua Debugger before, can you tell me what it is and how to use it?

Ok I found my code! It uses one VectorForce and every frame it calculates thrust, drag, and lift and then does VectorForce.Force = thrust + drag + lift. That was for a honey bee, so yours is probably going to be thrust + drag + jump.

Thrust

Thrust is a force in the direction you're walking. A force needs a mass and an acceleration. So, it'll look like

Thrust = MASS * ACCELERATION * MoveDirection

where MASS and ACCELERATION are constants. The mass will be the mass of your character. The acceleration adjusts how quickly we reach our desired speed.

Drag

Without a drag force, our thrust will continue to pick up speed. From what I recall, I used a basic drag force equation from my physics class.

Viscosity = MASS * ACCELERATION / MAX_VELOCITY
Drag = -Velocity * Viscosity

We already know what MASS and ACCELERATION are. The constant MAX_VELOCITY is the desired speed of your character. Those three make up Viscosity. The last variable to know is Velocity, which is the actual velocity of your character (not the velocity we want, but where it actually is). We probably don’t want jumping to interfere with the drag force for moving, so Velocity should only be on the x-z plane.

Velocity = Character.PrimaryPart.Velocity * Vector3.new(1, 0, 1)

This eliminates the y-component of the character’s velocity.

Jump

It seems that you already have jump figured out-- it's applying a force for a short amount of time. And then we're just gonna add that force at the very end like I said.

VectorForce.Force = Thrust + Drag + Jump

Hope this helps. Lmk if you have any questions.

EDIT: Fixed some formulas

3 Likes

I think it has something to do with the workspace’s gravity. (I’m not sure though)

I tried the method you showed above but the player doesn’t seem to be moving. It’s remains stationary if i give any input. It may be that I need to give it more power but I’m not sure.

Ummmm…

You need to use non euler to create a temporary conic so that you can multiply the semi major axis, semi major being the horizontal and semi minor being the vertical velocity units not actual velocity. Then set that to the cube as a position

Euler has a million things named after him. What does that mean in this context?

Which conic?


@HavocOmega
Here, I had a quick go at it. See if you can pick out anything that I’ve done that might be useful to you.
Moving.rbxl (28.8 KB)

EDIT: Ehhh I feel like this isn’t very helpful. If the LineForce was working then stick with what you got. Maybe you can manipulate the one LineForce to do both moving and jumping instead of a separate VectorForce for jumping.

4 Likes