How to fix teleport in the transition of a player from one position to the other

Godot Version

4.7.2

Question

Hello, so i used this code from one person in 3D scene, though the code was for 2D based game and in 2D environment it works smoothly.

The code is basically a character movement, they say like in pokemon, where you move based on a grid. The problem is that in 3D scene, after i replaced Vector2 with Vector3, the overall transition teleports player towards the given direction a little bit forward, then from there the player continues its transition actually smoothly and finishes as needed. I just need to remove this teleport thing.

extends CharacterBody3D

const tile_size = 7
var moving = false
var input_dir

func _physics_process(delta: float) -> void:
	input_dir = Vector3.ZERO
	if Input.is_action_just_pressed("ui_down"):
		input_dir = Vector3(0,0,1)
		move()
	elif Input.is_action_just_pressed("ui_up"):
		input_dir = Vector3(0,0,-1)
		move()
	elif Input.is_action_just_pressed("ui_right"):
		input_dir = Vector3(1,0,0)
		move()
	elif Input.is_action_just_pressed("ui_left"):
		input_dir = Vector3(-1,0,0)
		move()
	velocity = input_dir*10000*delta
	move_and_slide()	


func move():
	if input_dir:
		if moving == false:
			moving = true
			var tween = create_tween()
			tween.tween_property(self, "position", position+ input_dir*tile_size, 
			tween.tween_callback(move_false)
			
			
func move_false():
	moving = false

Your movement with velocity and move_and_slide is at ends with using a tween on position. I’d guess you want to remove the move_and_slide but you will have a harder time with collisions.

This tween based movement has caused issues before on the forum too, so here are some threads I remember that may help you.

Thanks for pointing out. Guess i will have to consider another method for movement