0 votes

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 "IdleF, IdleFL, IdleFR, IdleB, IdleBL, IdleBR, IdleL, IdleR" -------------------- 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. ("WalkingF, WalkingB, etc.")

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

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

func ready():
play(idle
anim_name);

func process(delta):
if (Input.is
actionpressed("uiright")):
velocity.x = movespeed;
elif (Input.is
actionpressed("uileft")):
velocity.x = -movespeed;
else:
velocity.x = 0;
if (Input.is
actionpressed("uiup")):
velocity.z = movespeed;
elif (Input.is
actionpressed("uidown")):
velocity.z = -movespeed;
else:
velocity.z = 0;
global
translate(velocity * delta)
var hvel = velocity;
h
vel.y = 0;
if (hvel.length() > 0):
if (animation != moving
animname):
play(moving
animname);
else:
if (animation != idle
animname):
play(idle
anim_name);

I have changed the coding to this:

extends AnimatedSprite3D

var movinganimname = "WalkingF";
var idle
animname = "IdleF";
var velocity = Vector3(0,0,0);
var move_speed = 2;

func ready():
play("Idle
F");

func process(delta):
if (Input.is
actionpressed("WalkRight")):
velocity.x += movespeed;
elif (Input.is
actionpressed("WalkLeft")):
velocity.x -= move_speed;
else:
velocity.x = 0;

if (Input.isactionpressed("WalkForward")):
velocity.z -= move
speed;
elif (Input.isactionpressed("WalkBackward")):
velocity.z += move
speed;
else:
velocity.z = 0;

global_translate(velocity * delta)

var hvel = velocity;
h
vel.y = 0;
if (hvel.length() > 0):
if (animation != moving
animname):
play("Walking
F");
else:
if(animation != idleanimname):
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?:

  1. How do I use the AnimatedSprite3D properly

  2. 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"

  3. 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 I just want to be able to switch between my animations during the user input moments

asked Oct 8 in Engine by KindoSaurProductions (16 points)
edited Oct 16 by KindoSaurProductions

1 Answer

0 votes

https://godotforums.org/discussion/21344/how-can-i-alternate-between-animations-during-user-input-with-a-animated-sprite3d-node#earliest

You need to scroll down before you can see the entire code
it was written on October 14th

answered Oct 16 by KindoSaurProductions (16 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.