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