More acceleration with move_and_collide?

Godot Version

4.5

Question

I am very new to godot and game development.

I am trying to create a flappy bird clone as a toy project. I created a CharacterBody2D and template code was created for me (very helpful btw). I stripped that template code down so that it only handles vertical movement.

extends CharacterBody2D
const JUMP_VELOCITY = -400.0

func _physics_process(delta: float) -> void:
	# Add the gravity.
	velocity += get_gravity() * delta

	# Handle jump.
	if Input.is_action_just_pressed("ui_accept"):
		velocity.y = JUMP_VELOCITY

	move_and_slide()

move_and_slide() is new to me so I wanted to see what would happen if I used move_and_collide(velocity) instead. It technically works, but the bird’s acceleration is way faster. In fact to get close to the template code’s speeds, I had to multiply the velocity by a tiny fraction like 0.02.

extends CharacterBody2D
const JUMP_VELOCITY = -400.0

func _physics_process(delta: float) -> void:
	# Add the gravity.
	velocity += get_gravity() * delta
			
	# Handle jump.
	if Input.is_action_just_pressed("ui_accept"):
		velocity.y = JUMP_VELOCITY

	#move_and_slide()
	move_and_collide(velocity*0.02)

After reading the docs, I understand I could just make my game with move_and_slide(). But I want to know why the acceleration is so much higher with move_and_collide(). I didn’t find anything in the documentation that would specifically explain this behavior besides this statement:

move_and_slide() may also recalculate the kinematic body’s velocity several times in a loop as, to produce a smooth motion, it moves the character and collides up to five times by default. At the end of the process, the character’s new velocity is available for use on the next frame.

I would love a further explanation of that statement if it is relevant.

Thanks!

move_and_collide() expect the motion vector (change in position) as its argument, not velocity.

1 Like

I figured it out. I was providing move_and_collide with the velocity and not the velocity * delta.

1 Like