I'm not sure that I have any problem that's going to prevent me from finishing my indie game now but, I anticipate that their will be more problems in the future if I merely follow tutorials without understanding what I'm actually doing. So I'm just here trying to understand certain concepts, so I can use them more freely and more creatively.

I notice that velocity and move_and_slide behaves differently than it did in Godot 4. However, I don't fully understand to what extend it behaves differently. Sometimes I can make movement happen with the move_and_slide (or move_and_collide) function by just manipulating the velocity. However, other times, I can't make it happen I also haven't experimented with the code enough to know the implications of getting the kinematic body to move without the move_and_slide function. Could anyone explain that to me?
For example, I can get my player to move with this code right here:

func movement_code(delta):
	var horizontal_velocity = Input.get_vector("move_left","move_right","move_forward","move_backward").normalized() * player.speed
	var global_transform_basis = player.global_transform.basis
	player.velocity = horizontal_velocity.x * global_transform_basis.x + horizontal_velocity.y * global_transform_basis.z
	if player.is_on_floor():
		player.velocity_y = 0
		if Input.is_action_just_pressed("Jump"):
			player.velocity_y = jump_velocity
	else:player.velocity_y -= gravity * delta
	player.velocity.y = player.velocity_y
	player.move_and_slide()

I also can make an enemy "follow" the player with the code over here as well:

func follow_player_demo(move_speed = 2.0):
	var dir_2_player = player.global_position - enemy.global_position #direction to player.
	dir_2_player.y = 0 
	dir_2_player = dir_2_player.normalized() 	
	enemy.velocity = dir_2_player * move_speed #The enemy's velocity is the dir_2_player multiplied by move_speed.
	enemy.move_and_slide()

In either cases, the move_and_slide() is a neccesity; both functions can't work without move_and_slide. However, I can also make the enemy move with a code like this:

	enemy.velocity.x += 0.05

Again, I don't see any problems here. I just want to know what's going on and what potential problems could come up. I've been getting more creative with coding but, I'm also cautious.

  • xyz replied to this.
  • Audiobellum A kinematic body shouldn't move at all without a call to move_and_*(). The only thing that could potentially move it is a push due to collision resolve.

    Audiobellum A kinematic body shouldn't move at all without a call to move_and_*(). The only thing that could potentially move it is a push due to collision resolve.

      xyz I just discovered that move_and_slide was becoming called elsewhere on the enemy's state machine. Still, I'm surprised by how easy it is to use now. Imposter syndrome got me being too cautious.