• Godot HelpProgramming
  • How can I alternate between animations during user Input with a Animated Sprite3D node?[ANSWERED]

Hi I've trouble with making my Sprite (3D) altenate between an "Idle" animation and a "Walking" animation.

I was able to find a page where this question was also asked ----- ( https://godotforums.org/discussion/20361/how-do-i-play-an-animatedsprite3d-when-i-am-moving ) ------ ,

but it was ment for a node that I've never heard of ----- ( I am talking about AnimatedSprite3D node ) ------.

I tried looking it up to see if there were any tutorials on this particualar node, but there wasn't anyone talking about it, but I do need it to make my Sprite move in the 3D enviroment.

In the AnimatedSprite3D node you use frames from your spritesheet to make a quick animation of your character without doing the work around of a Sprite3D node and AnimationPlayer. (this is my intrepertation soo this might be wrong).

So what have I done:

  • In the AnimatedSprite3D I made an "Idle" animation in 8 directions named "Idle_F, Idle_FL, Idle_FR, Idle_B, Idle_BL, Idle_BR, Idle_L, Idle_R" -------------------- F = Forward, B= Backward, L = Left and R = Right -----------------
  • I did the same thing with the "Walking" animation and named it in the same style as the "Idle" one. ("Walking_F, Walking_B, etc.")

In case you haven't clicked on the link, the coding is as follows:

extends AnimatedSprite3D
var moving_anim_name = "moving";
var idle_anim_name = "idle";
var velocity = Vector3(0,0,0);
var move_speed = 20;

func _ready():
	play(idle_anim_name);

func _process(delta):
	if (Input.is_action_pressed("ui_right")):
		velocity.x = move_speed;
	elif (Input.is_action_pressed("ui_left")):
		velocity.x = -move_speed;
	else:
		velocity.x = 0;
	if (Input.is_action_pressed("ui_up")):
		velocity.z = move_speed;
	elif (Input.is_action_pressed("ui_down")):
		velocity.z = -move_speed;
	else:
		velocity.z = 0;
	
	global_translate(velocity * delta)
	var h_vel = velocity;
	h_vel.y = 0;
	if (h_vel.length() > 0):
		if (animation != moving_anim_name):
			play(moving_anim_name);
	else:
		if (animation != idle_anim_name):
			play(idle_anim_name);

I have changed the coding to this:

extends AnimatedSprite3D

var moving_anim_name = "Walking_F";
var idle_anim_name = "Idle_F";
var velocity = Vector3(0,0,0);
var move_speed = 2;

func _ready():
	play("Idle_F");

func _process(delta):
	if (Input.is_action_pressed("Walk_Right")):
		velocity.x += move_speed;
	elif (Input.is_action_pressed("Walk_Left")):
		velocity.x -= move_speed;
	else:
		velocity.x = 0;
	
	if (Input.is_action_pressed("Walk_Forward")):
		velocity.z -= move_speed;
	elif (Input.is_action_pressed("Walk_Backward")):
		velocity.z += move_speed;
	else
		velocity.z = 0;
	
	global_translate(velocity * delta)
	
	var h_vel = velocity;
	h_vel.y = 0;
	if (h_vel.length() > 0):
		if (animation != moving_anim_name):
			play("Walking_F");
	else:
		if(animation != idle_anim_name):
			play("Idle_F");

What I see now is as follows after making the animations and code

Left Right Up Down play the Animation of " walking forward (Walking_F) " this is good but also bad because

Left Right and Down don't show the correct animation

also the character keeps accelerating and proceeds to slide in the same direction, when pressing the opposite direction or just stopping.

After all this what are my questions?:

How do I use the AnimatedSprite3D properly

What do I need to do to make my characters' animation work in all 8 directions? So when the player presses Up("W") the character will Walk Forward + animation. This also needs to happen for the "Forward Left", "Forward Right", "Backward Right" and "Backward Left"

Lastly if you were also making a 2D sprite in a 3D world game and already figured another way to display the animation in all 8 directions. Could you please explain or show it to me?

Thanks for reading this post,

Kellin (KindoSaur_Productions)

PS: if you have the coding for only the Sprite3D than that wil be alright as well

(TwistedTwigleg edit: Fixed the format for the posted code and added indentation so the code is a little more readable)

I see you used quotation instead of code formatting thus the indentation is missing from your code. Might be useful to try posting the code again with the formatting intact.

When in doubt you could use a github gist or pastebin to host your code snippet and then paste the link to your post, it will get embedded from that.

5 days later

I'm not totally sure how to answer all of the questions, but here is what I would try:

  • For how to use AnimatedSprite3D nodes, I would put "Godot AnimatedSprite" in your search engine of choice and learn about the AnimateSprite node. The AnimatedSprite3D node works exactly the same, just in 3D instead of 2D.
  • For changing animations based on movement going in eight directions, you just need to know roughly which direction the player is moving towards and/or where the camera is facing. There are many other ways to do it, which may work, so I'm not sure what the best way would be. I wrote a simple implementation below that might help give an idea of how it can be done.
  • I have done very little 2D sprites in 3D worlds, so I'm afraid I do not know of any alternative solutions right off. You could animate a Sprite3D node using an AnimationPlayer node and creating the animations there, which may give you some additional flexibility.

Here is one way you could handle changing the animation based on input from the player (untested):

extends AnimatedSprite3D

var moving_anim_name = "Walking_F";
var idle_anim_name = "Idle_F";
var velocity = Vector3(0,0,0);
var move_speed = 2;

# variables to track which input keys have been pressed:
var input_vector = Vector3.ZERO;

func _ready():
	play("Idle_F");

func _process(delta):
	
	if (Input.is_action_pressed("Walk_Right")):
		velocity.x += move_speed;
		input_vector.x = 1
	elif (Input.is_action_pressed("Walk_Left")):
		velocity.x -= move_speed;
		input_vector.x = -1
	else:
		velocity.x = 0;
	
	if (Input.is_action_pressed("Walk_Forward")):
		velocity.z -= move_speed;
		input_vector.z = -1
	elif (Input.is_action_pressed("Walk_Backward")):
		velocity.z += move_speed;
		input_vector.z = 1
	else
		velocity.z = 0;
	
	global_translate(velocity * delta)
	
	var h_vel = velocity;
	h_vel.y = 0;
	if (h_vel.length() > 0):
		if (input_vector.z <= -1):
			if (input_vector.x <= -1):
				_change_sprite_animation("Walking_FL")
			elif (input_vector.x >= 1):
				_change_sprite_animation("Walking_FR")
			else:
				_change_sprite_animation("Walking_F")
		elif (input_vector.z >= 1):
			if (input_vector.x <= -1):
				_change_sprite_animation("Walking_DL")
			elif (input_vector.x >= 1):
				_change_sprite_animation("Walking_DR")
			else:
				_change_sprite_animation("Walking_D")
	else:
		if (input_vector.z <= -1):
			if (input_vector.x <= -1):
				_change_sprite_animation("Idle_FL")
			elif (input_vector.x >= 1):
				_change_sprite_animation("Idle_FR")
			else:
				_change_sprite_animation("Idle_F")
		elif (input_vector.z >= 1):
			if (input_vector.x <= -1):
				_change_sprite_animation("Idle_DL")
			elif (input_vector.x >= 1):
				_change_sprite_animation("Idle_DR")
			else:
				_change_sprite_animation("Idle_D")

# A simple helper function for changing animations
func _change_sprite_animation(new_animation_name):
	if (animation != new_animation_name):
		play(new_animation_name);

It is not the most neat or tidy way of handling it, but it should hopefully work. You might want to look into refactoring the code, maybe moving it into a function, for easier maintenance in the future. The biggest thing is that you just need a way to track the direction the player is moving towards. For the code above, I just used a Vector3 and a bunch of if statements as a way to track which direction the player is moving towards.


Additionally, here are a couple Youtube videos I found online that may help, if you are wanting to make something like the 3D sprites in the game Doom:

  • How to make a 8 directional billboard sprite in Godot Engine 3 (Youtube)
  • How to make Doom-style directional sprites in Godot (Youtube)

Hopefully this helps :smile:

My God! You are amazing! It is working, but there is 1 slight problem. The walking animations for Left and Right don't get a signal from the code, so when I use "A" or "D" it will show the animation of walking Forward_Left or Right.

I am going to look if I am able to fix it. You will be updated soon enough.

Thanks :)

Edit: I do know why "Left" and "Right" aren't getting a signal from the code... the _changed_sprite_animation("Walking_L") and _change_sprite_animation("Walking_R") weren't in the lines of codes so with a bit of tweeking I might get it to work.

Edit 2: I also found another problem: When you go forward it plays the forward animation and when you decide to head left and forward it will play the animations needed for it, but when you want to go back to the animation of walking forward it get's stuck on walking Forward_Left or Forward_Right (it does switch when pressing Left or Right Forward )

The issue with left and right was an oversight on my part, I totally forgot to add them. The issue with the animation not resetting is because the code doesn't set input_vector back to zero if the input is no longer being pressed.

Both issues are relatively easy to solve by changing the code a bit. Below is the, hopefully, fixed code:

extends AnimatedSprite3D

var moving_anim_name = "Walking_F";
var idle_anim_name = "Idle_F";
var velocity = Vector3(0,0,0);
var move_speed = 2;

# variables to track which input keys have been pressed:
var input_vector = Vector3.ZERO;

func _ready():
	play("Idle_F");

func _process(delta):
	
	if (Input.is_action_pressed("Walk_Right")):
		velocity.x += move_speed;
		input_vector.x = 1
	elif (Input.is_action_pressed("Walk_Left")):
		velocity.x -= move_speed;
		input_vector.x = -1
	else:
		velocity.x = 0;
		input_vector.x = 0
	
	if (Input.is_action_pressed("Walk_Forward")):
		velocity.z -= move_speed;
		input_vector.z = -1
	elif (Input.is_action_pressed("Walk_Backward")):
		velocity.z += move_speed;
		input_vector.z = 1
	else
		velocity.z = 0;
		input_vector.z = 0
	
	global_translate(velocity * delta)
	
	var h_vel = velocity;
	h_vel.y = 0;
	# Walking animations below:
	if (h_vel.length() > 0):
		if (input_vector.z <= -1):
			if (input_vector.x <= -1):
				_change_sprite_animation("Walking_FL")
			elif (input_vector.x >= 1):
				_change_sprite_animation("Walking_FR")
			else:
				_change_sprite_animation("Walking_F")
		elif (input_vector.z >= 1):
			if (input_vector.x <= -1):
				_change_sprite_animation("Walking_DL")
			elif (input_vector.x >= 1):
				_change_sprite_animation("Walking_DR")
			else:
				_change_sprite_animation("Walking_D")
		else:
			if (input_vector.x <= -1):
				_change_sprite_animation("Walking_L")
			elif (input_vector.x >= 1):
				_change_sprite_animation("Walking_R")
	# Idle animations below:
	else:
		if (input_vector.z <= -1):
			if (input_vector.x <= -1):
				_change_sprite_animation("Idle_FL")
			elif (input_vector.x >= 1):
				_change_sprite_animation("Idle_FR")
			else:
				_change_sprite_animation("Idle_F")
		elif (input_vector.z >= 1):
			if (input_vector.x <= -1):
				_change_sprite_animation("Idle_DL")
			elif (input_vector.x >= 1):
				_change_sprite_animation("Idle_DR")
			else:
				_change_sprite_animation("Idle_D")
		else:
			if (input_vector.x <= -1):
				_change_sprite_animation("Idle_L")
			elif (input_vector.x >= 1):
				_change_sprite_animation("Idle_R")

# A simple helper function for changing animations
func _change_sprite_animation(new_animation_name):
	if (animation != new_animation_name):
		play(new_animation_name);

That should hopefully solve both of the issues :smile:

Hey it works, but yet again a new problem has risen sadly enough :'(

Ok so now it switches between the animations like it should DOWN UP RIGHT LEFT and the Diagonals work as well. But now the animation to it's idle-pose is stuck somewhere and can't be played (I mean the when you start walking, but the walk animation will keep playing even though you stopped pressing a key).

What I found weird is that in the untested code it was able to switch between these states like it should, but the Left, Right, Up and Down states were cancelled and was replaced by only the Diagonal Animations.

So I went digging in the untested and the new code to see if there was a difference (beside the added Left and Right Idle- and Moving animation) and I found a very important "suspect" who caused this issue:

In the picture you see 2 of the codes Left (the new code with the added Left and Right) and Right (the old with the animation problem of being stuck on the diagonals)

I saw that for the Left and Right to play the input_vector.x = 0 was added. This did help out the problem of the old one, but created a new one with the switching. So I figured that I deleted this line (Same for the input_vector.z = 0) this brought me back to the issue I had with the old code.

The only thing that I can think of that is that the new lines cancel eachother through confusion on whether the button is pressed or not.

We are so close to this one though and you have helped me a TON! so many many many thanks from me to you already =) <3

PS: I don't want to be annoying with all of this, sorry if I am haha :)

Edit: I am sometimes very bad in Phrasing of what I want to say, because English is my second language ?

@KindosaurGaming said: Hey it works, but yet again a new problem has risen sadly enough :'(

Ok so now it switches between the animations like it should DOWN UP RIGHT LEFT and the Diagonals work as well. But now the animation to it's idle-pose is stuck somewhere and can't be played (I mean the when you start walking, but the walk animation will keep playing even though you stopped pressing a key).

Hmm, well this issue is a tad more tricky, because the solution for allowing the left/right animations to play is exactly what is causing the issue with the idle animation. I can think of several different ways to fix the issue, though I'm not sure which would be the easiest and/or best.

Probably the most straightforward is to store the last direction the player moved towards in a variable, and then use that variable for the idle animations:

extends AnimatedSprite3D

var moving_anim_name = "Walking_F";
var idle_anim_name = "Idle_F";
var velocity = Vector3(0,0,0);
var move_speed = 2;

# variables to track which input keys have been pressed:
var input_vector = Vector3.ZERO;
var last_directional_input = Vector3.ZERO;	

func _ready():
	play("Idle_F");

func _process(delta):
	
	if (Input.is_action_pressed("Walk_Right")):
		velocity.x += move_speed;
		input_vector.x = 1
	elif (Input.is_action_pressed("Walk_Left")):
		velocity.x -= move_speed;
		input_vector.x = -1
	else:
		velocity.x = 0;
		input_vector.x = 0
	
	if (Input.is_action_pressed("Walk_Forward")):
		velocity.z -= move_speed;
		input_vector.z = -1
	elif (Input.is_action_pressed("Walk_Backward")):
		velocity.z += move_speed;
		input_vector.z = 1
	else
		velocity.z = 0;
		input_vector.z = 0
	
	global_translate(velocity * delta)
	
	# If the input_vector is NOT zero, then we want to store the direction
	# for the idle animation.
	if (input_vector != Vector3.ZERO):
		last_directional_input  = input_vector
	# last_directional_input should always contain the direction the player
	# is moving towards if the player is moving, or the last direction the player
	# moved towards if the player is no longer moving.
	# Now we can replace input_vector with last_directional_input for
	# animations.

	var h_vel = velocity;
	h_vel.y = 0;
	# Walking animations below:
	if (h_vel.length() > 0):
		if (last_directional_input .z <= -1):
			if (last_directional_input .x <= -1):
				_change_sprite_animation("Walking_FL")
			elif (last_directional_input .x >= 1):
				_change_sprite_animation("Walking_FR")
			else:
				_change_sprite_animation("Walking_F")
		elif (last_directional_input .z >= 1):
			if (last_directional_input .x <= -1):
				_change_sprite_animation("Walking_DL")
			elif (last_directional_input .x >= 1):
				_change_sprite_animation("Walking_DR")
			else:
				_change_sprite_animation("Walking_D")
		else:
			if (last_directional_input .x <= -1):
				_change_sprite_animation("Walking_L")
			elif (last_directional_input .x >= 1):
				_change_sprite_animation("Walking_R")
	# Idle animations below:
	else:
		if (last_directional_input .z <= -1):
			if (last_directional_input .x <= -1):
				_change_sprite_animation("Idle_FL")
			elif (last_directional_input .x >= 1):
				_change_sprite_animation("Idle_FR")
			else:
				_change_sprite_animation("Idle_F")
		elif (last_directional_input .z >= 1):
			if (last_directional_input .x <= -1):
				_change_sprite_animation("Idle_DL")
			elif (last_directional_input .x >= 1):
				_change_sprite_animation("Idle_DR")
			else:
				_change_sprite_animation("Idle_D")
		else:
			if (last_directional_input .x <= -1):
				_change_sprite_animation("Idle_L")
			elif (last_directional_input .x >= 1):
				_change_sprite_animation("Idle_R")

# A simple helper function for changing animations
func _change_sprite_animation(new_animation_name):
	if (animation != new_animation_name):
		play(new_animation_name);

I don't know if the code above will work though. If it doesn't, then I can see about making a test project and playing around with the code directly. I think it will work though.

We are so close to this one though and you have helped me a TON! so many many many thanks from me to you already =) <3

PS: I don't want to be annoying with all of this, sorry if I am haha :)

Edit: I am sometimes very bad in Phrasing of what I want to say, because English is my second language ?

No problem! Do not worry, you are not annoying me. I am helping because I want to, not because I feel obligated or anything. It is all good :)

IT WORKS !!!! B) You're amazing thanks alot =) I see no problems with the code and also no glitches in the sprites.

Last thing if I want my character to switch between sprinting, walking or jumping is it possible to use the same code with adding only the direction and animation

or is that more complecated than that...

Great! I'm glad the code works.

Adding additional mechanics like running/sprinting/walking/jumping etc should be possible, you'll just need a way to track what the player is doing and then use the proper animation in the proper direction. Theoretically it should not be too difficult, but it really depends on your game, the code, and the requirements of the game.

I would recommend considering breaking the animation code out into functions (or maybe state machines) for easier management if you have many different mechanics for the player. It is not required by any means, but it might make it a tad easier to see what is going on when debugging and writing code, as you can keep things separate from each other.

Regardless, the best way to know for sure would be to prototype and see what happens! :smile:

One last question I have posted this problem on more places than this, but without your the right answer like what you have to me. So Is it alright to post the full (correct) code on those other forums?

I want to do this, because I was searching for more than 7 weeks for the final solution and thats insane especially since the idea is for most people uncommon or hard. Like making a 3D game with 2D elements is way harder than what I already thought, so it might be more for the people who want to know what you need to do and what code you need to use.

Thanks ?

I doubt that @TwistedTwigleg would have a problem with it, but you could also just link to the post(s) here, if/when in doubt.

@KindosaurGaming said: One last question I have posted this problem on more places than this, but without your the right answer like what you have to me. So Is it alright to post the full (correct) code on those other forums?

I want to do this, because I was searching for more than 7 weeks for the final solution and thats insane especially since the idea is for most people uncommon or hard. Like making a 3D game with 2D elements is way harder than what I already thought, so it might be more for the people who want to know what you need to do and what code you need to use.

Thanks ?

Sure! I have no issues with it! Feel free to link the forum post anywhere you see fit.

Hey @TwistedTwigleg I have one last question one that I should have asked a bit earlier.

I wanted to test my camera with 3D movement (spinning around the character) and I noticed that the code goes for the global movement instead of the local movement of my character. what I mean is that when I walk forward( -z ), turn the camera to the right ( x ) it will continue walking down the -Z-axis instead of the X-axis

how can I fix that iniside of your code. Cuz I did spot a video explaining this movement, but he was tinkering on the velocity and that is also the part that lets the animation be played.

link is here for the video:

So I followed his tutorial and that made the played scene crash so I did reset everything and I am still on the old code you gave me, so no worries there

@KindosaurGaming said: Hey @TwistedTwigleg I have one last question one that I should have asked a bit earlier.

I wanted to test my camera with 3D movement (spinning around the character) and I noticed that the code goes for the global movement instead of the local movement of my character. what I mean is that when I walk forward( -z ), turn the camera to the right ( x ) it will continue walking down the -Z-axis instead of the X-axis

how can I fix that iniside of your code.

You need to use the Camera node's directional vectors to manipulate velocity instead of changing velocity on the x and z axes. You just need to make a few minor changes:

First you need to have a reference to the Camera node, so the following class variables will need to be added:

# Old code, just here for reference.
var input_vector = Vector3.ZERO;
var last_directional_input = Vector3.ZERO;  
# New variables! This will allow use the Camera node
export (NodePath) var path_to_camera_view;
var view_camera;

and then we need to replace lines 17 to 35 in the code I posted last with the following:

# get the camera's local X and Z axis.
# we need this so we can move the player relative to the camera's view.
# (the Z axis is negative because the camera faces the -Z axis)
var view_camera_right = view_camera.global_transform.basis.x;
var view_camera_forward = -view_camera.global_transform.basis.z;
# Remove the Y axis so the player cannot go flying
view_camera_right.y = 0
view_camera_forward.y = 0;
# Normalize the vectors so the Camera's scale does not change the movement speed
view_camera_right = view_camera_right.normalized();
view_camera_forward = view_camera_forward.normalized();
# Now we can use these variables to move the player!
# First, we need to cancel out the velocity entirely, as we are (potentially)
# manipulating multiple axes at a time, so we cannot just reset the X/Z axes
# like before.
velocity = Vector3.ZERO;

if (Input.is_action_pressed("Walk_Right")):
	velocity += view_camera_right * move_speed;
	input_vector.x = 1
elif (Input.is_action_pressed("Walk_Left")):
	velocity.x -= view_camera_right * move_speed;
	input_vector.x = -1
else:
	input_vector.x = 0

if (Input.is_action_pressed("Walk_Forward")):
	velocity += view_camera_forward * move_speed;
	input_vector.z = -1
elif (Input.is_action_pressed("Walk_Backward")):
	velocity.z -= view_camera_forward * move_speed;
	input_vector.z = 1
else:
	input_vector.z = 0

Then the player should move relative to the rotation of the camera :smile:

It gives me an error message and I am not really sure what I did wrong

export (KinematicBody/AnimatedSprite3D/Head/Camera) var path_to_camera_view; Head is a spatial node.

export (NodePath) var path_to_camera_view; Invaldid operands for operator

Might it be you have 2D and 3D nodes mixed in your hierarchy?

export (NodePath) var path_to_camera_view should work, but you'll need to point the NodePath to the Camera node you are using in the Godot editor, not in the code itself. NodePath is an object and by using the export keyword, you can expose the object to the Godot editor so the variable can be set from the Godot editor. If use export (NodePath) var path_to_camera_view and select the AnimatedSprite3D node in the editor, you should find that in the inspector you can assign path_to_camera_view to a node in the scene through the Godot editor.


Looking at my post, I forgot a step. You'll also need to add the following to the _ready function:

view_camera = get_node(path_to_camera_view)

Or if you do not want to use an exported NodePath and camera is a child node of the player, then you can instead just use get_node:

view_camera = get_node("Head/Camera")

@Megalomaniak said: Might it be you have 2D and 3D nodes mixed in your hierarchy?

My hierarchy of the nodes is as follows: Spatial Node (named World) -> MeshInstance (used for a plane to walk on: Not Important) (Extra Nodes inside) -> Sprite3D (ment for a different character: Not Important) (Also has extra nodes inside) -> KinematicBody (the player) - - -> CollisionShape - - -> AnimatedSprite3D - - - - - -> Spatial Node (named Head) - - - - - -> Camera

I have also used the copy paste funtion of the Node route so I am not really sure :/

@TwistedTwigleg said: export (NodePath) var path_to_camera_view should work, but you'll need to point the NodePath to the Camera node you are using in the Godot editor, not in the code itself. NodePath is an object and by using the export keyword, you can expose the object to the Godot editor so the variable can be set from the Godot editor. If use export (NodePath) var path_to_camera_view and select the AnimatedSprite3D node in the editor, you should find that in the inspector you can assign path_to_camera_view to a node in the scene through the Godot editor.


Looking at my post, I forgot a step. You'll also need to add the following to the _ready function:

view_camera = get_node(path_to_camera_view)

Or if you do not want to use an exported NodePath and camera is a child node of the player, then you can instead just use get_node:

view_camera = get_node("Head/Camera")

I have used the second command view_camera = get_node("Head/Camera") and my main scene when played crashes.

It was able to play and it did show the character it was also possible to walk forward and right when the camera was rotated. But Left and Down will crash the scene.

I also think that I wasn't really clear on what needs to happen (sorry for that :# ). The thing is is that I would like to see that you can walk around to where the camera is looking at. So both X axis (Positive and Negative) and Z-axis (Positive and Negative)

Because what happend befor was that the character got stuck on only the X and Z axis eventhough the camera was facing in the opposit direction.

@KindosaurGaming said:

view_camera = get_node("Head/Camera")

I have used the second command view_camera = get_node("Head/Camera") and my main scene when played crashes.

It was able to play and it did show the character it was also possible to walk forward and right when the camera was rotated. But Left and Down will crash the scene.

Ah, my bad. The issue is the code for left and down is changing velocity.x instead of velocity. I think that is what was causing it to crash. The following code should work:

var view_camera_right = view_camera.global_transform.basis.x;
var view_camera_forward = -view_camera.global_transform.basis.z;

view_camera_right.y = 0
view_camera_forward.y = 0;

view_camera_right = view_camera_right.normalized();
view_camera_forward = view_camera_forward.normalized();

velocity = Vector3.ZERO;

if (Input.is_action_pressed("Walk_Right")):
	velocity += view_camera_right * move_speed;
	input_vector.x = 1
elif (Input.is_action_pressed("Walk_Left")):
	velocity -= view_camera_right * move_speed;
	input_vector.x = -1
else:
	input_vector.x = 0

if (Input.is_action_pressed("Walk_Forward")):
	velocity += view_camera_forward * move_speed;
	input_vector.z = -1
elif (Input.is_action_pressed("Walk_Backward")):
	velocity -= view_camera_forward * move_speed;
	input_vector.z = 1
else:
	input_vector.z = 0

I also think that I wasn't really clear on what needs to happen (sorry for that :# ). The thing is is that I would like to see that you can walk around to where the camera is looking at. So both X axis (Positive and Negative) and Z-axis (Positive and Negative)

Because what happend befor was that the character got stuck on only the X and Z axis eventhough the camera was facing in the opposit direction.

I'm not totally sure what you mean. You want the character to walk relative to the camera, right? Where when you press up the character moves upwards relative to how the camera is positioned, likewise for down, left, and right? Like the end result of the KidsCanCode video you link, right? The code posted above should do that, once it isn't crashing due to a typo on my part.

If that is not what you are looking for, can you provide a reference to what you are looking for? Like a link to a game and/or a video that shows the type of movement you are wanting to achieve. I cannot guarantee that I'll be able to help, but it might help me better understand what you are looking for. :smile: