character moving speed changes when fps changes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sbhnP

I have a kinematic 2d which moves with MoveAndSlide(velocity, Vector.Up) in _process
Lag doesn’t change horizontal moving speed and it moves always with the same speed but jump height is always changing with fps
How to solve that?
Also there isn’t such a problem while i use the code with _physicsProcces .but i can’t use that because it causes lag when a there is a lot of nodes with that script in tree

void Jump()
{
velocity.y=-JumpForce;
}
void Move()
{
velocity.y+= Gravity;
velocity.x=MovementSpeed;
}
public override void _Process(float delta)
{
velocity=MoveAndSlide (velocity, Vector.Up)
}
:bust_in_silhouette: Reply From: matthewjw

I too am a noob so I may be getting this wrong, please correct me if so:

  • delta is the time since the last frame

  • this means your movement speed will change based on FPS

  • you need to multiply the variable you are calling in process() by delta to make sure it is occurring per second, and not per frame. velocity = delta * MoveAndSlide(…)