Godot: move_and_slide has different results with different fps

Created on 5 Mar 2020  路  8Comments  路  Source: godotengine/godot

Godot version:
3.2.stable.official (Steam)

OS/device including version:
macOS Catalina 10.15.2

Issue description:
When I "jump" using move_and_slide with 60 fps and 10 fps, I'm having different results (jump height).

extends Node
var motion := Vector2(0, 10)
func _process(delta):
  if $KinematicBody2D.is_on_floor() and Input.is_action_just_pressed("ui_accept"):
    motion.y = -100
  else:
    motion.y += 10
  $KinematicBody2D.move_and_slide(motion, Vector2.UP)
  if motion.y == 0:
    print($KinematicBody2D.position.y)

60 fps:
196.642624
196.753326
196.753433
196.753403
196.753448

10 fps:
150.681808
150.29213
150.920074
150.920074
150.920074

Steps to reproduce:

  • Create a scene with a StaticBody2d (used as a floor) and a KinematicBody2d (the player)
  • Use the code put above
  • Check the numbers with regular fps
  • Limit fps to 10
  • Check the numbers again

Screen Shot 2020-03-05 at 2 30 09 AM

Minimal reproduction project:
test_fps.zip

documentation physics

Most helpful comment

We should have warnings between _process and _physics_process

Input should have warnings in _physics_process
move_and_slide, move_and_collide should have warnings in _process

All 8 comments

move_and_slide() should be used in _physics_process() and not _process()

This definitely needs to be documented better, however. We'll use this issue to track that.

We should have warnings between _process and _physics_process

Input should have warnings in _physics_process
move_and_slide, move_and_collide should have warnings in _process

I'm new to Godot contribution community. I'd like to work on this issue.

@theoway No need to ask permission, you can just get started. Be sure to read PR workflow (or watch this video) to get familiar with the pull request workflow. The files you want to edit are doc/classes/KinematicBody2D.xml and doc/classes/KinematicBody.xml.

Once #33653 is merged, you'll be able to use move_and_slide() in _process()聽by passing the delta parameter as follows:

func _process(delta):
    var motion = Vector2(100, 0)
    move_and_slide(motion, delta)

Still, we should document the current limitation by telling people to use move_and_slide() only in _physics_process().

@aaronfranke Thanks for the information. I'll start editing the documentation.

I've made a PR for change in docs. #36849

Was this page helpful?
0 / 5 - 0 ratings