How to move player to a certain distance from whatever angled position he is

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By FerozAkbar

Hello guys, I want the player to be moved inside and outside based on keypress. The problem is as the player can be at any angle any time , I’m not able to understand how to move him to some distance inside/outisde.

with the help of this article https://kidscancode.org/godot_recipes/2d/2d_align_surface/

I have did this

snap = transform.y * 128 if !is_jumping else Vector2.ZERO
velocity.y += GRAVITY * delta + force
velocity.x += 1
velocity = velocity.normalized() * SPEED
velocity = move_and_slide_with_snap(velocity.rotated(rotation),snap,-transform.y,true,4,PI/3,false)
velocity = velocity.rotated(-rotation)

please help

:bust_in_silhouette: Reply From: dethland

I have an idea to fake it. You could use two sprites to represent the player. When the key is pressed, you could hide one sprite and show another one. Using this method, the player position could be consistent. You don’t need to change the player’s position according to the platform. However, you may need to rotate the player to fit it.