Hi all. I understandthe way move_and_slide() works in 2d. But, when I try to use it in 3D movement, it does not work. Am I missing something? Please, if someone could help.
Let me explain:
if I press "forward" the character moves in th direction of Vector3(0,0,-1). but, if I turn the player left or right, it still moves in the same world direction. and not in the direction that the player is facing. Any help that could clear this to me, would be appreciated. Thank you all in advance.
Her's the code I wrote:
extends KinematicBody2D
var dir = Vector2()
func _ready():
set_physics_process(true)
pass
func _process(delta):
pass
func _physics_process(delta):
move_and_slide(dir,Vector2.UP)
move_and_collide(Vector2(0,1))
if Input.is_action_pressed("ui_right"):
$AnimatedSprite.play("run")
print("right")
dir = Vector2(50,1)
elif Input.is_action_pressed("ui_left"):
$AnimatedSprite.play("run")
print("left")
dir = Vector2(-50,1)
elif Input.is_action_pressed("ui_accept") and is_on_floor():
$AnimatedSprite.play("idle")
print("jump")
dir = Vector2(0,-5000)
else:
dir = Vector2(0,2)
$AnimatedSprite.play("idle")
pass