Hi, I'm currently working on a 2dhd game. My character controller uses a standard script with some tweaks to manage the AnimatedSprite3D animations.
I'm having trouble on making the movement relative to camera, rather than the whole space itself: when the player presses Q or E keys, the camera rotates of 45deg (left or right), though the player doesn't change it's direction as relative to it
What would be the best way of doing that?
this is my current player movement function (the auxiliary functions are just to update the animations based on the input vector direction)
func _physics_process(delta):
if not is_on_floor():
velocity.y -= gravity * delta
if not InputManager.isinputblocked:
var input_dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
update_animation(input_dir)
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
update_idle_animation()
move_and_slide()