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