#Need help with character walking in current scene

1 messages · Page 1 of 1 (latest)

green mortar
#

I am new Godot and started a course on Udemy and the version of the tutorial is a 4.3 version and I am currently running a 4.4 version and I have followed along so far on movement when writing GDScript and after clicking run current scene all my character can do is jump while also in the idle animation but won't do any walking and I currently have 0 idea on where I went wrong in the code in GDscript oh and ChatGPT and Grok don't work at all

olive locust
#

You'll need to share your code if you want us to help you

green mortar
patent mountain
#

your if is always true, so you're not applying velocity to xz.

green mortar
#

how to do I fix it?

olive locust
patent mountain
#

that is true a Vector3 will be cast to false if it has no movement, but ins't that the opposite that you want?

jaunty river
green mortar
#

you mean get rid of Velocity.x and Velocity. Y on 45 and 46?

patent mountain
#

no just de ident it

jaunty river
#

No
Lower indentation

patent mountain
#

make it part of the parent identantion

olive locust
#

Shift+tab

patent mountain
#

basically the if there is just setting xz to the velocity if movement is false, instead of setting _xz var and seeting velocity later.

green mortar
#

These two I have here on 44-46 _xz_velocity.x = _xz_velocity.x
_xz_velocity.z = _xz_velocity.z but when i run current scene no movement is happening the only other ones are under the _if direction and the else: line

#

i literally have no idea what im doing

patent mountain
#

basically your 37-46

#

should be like this instead

#
if _direction:
  _xz_velocity = ...
else:
  _xz_velocity = ...
  _animation_set = ...

velocity.x = _xz_velocity.x
velocity.z = _xz_velocity.z
#

notice that velocity is at the same level as the if statement, not nested on the else statement.

green mortar
#

so just _xz_velocity = ... instead of what I have with the move_toward something something

#

?

patent mountain
#

no ... is just so I dont copy everything.

#

everything should be fine there but those 2 last lines

#

they should be in the if level, not nested.

#

because gdscript is an indentation language you need to pay a bit more attention to it ( I hate this about gdscript tbf )

#

so in another language it would be more like

if _direction {
  _xz_velocity = ...
} else {
  _xz_velocity = ...
  _animation_set = ...
} # as you can see the velocity is not inside the else

velocity.x = _xz_velocity.x
velocity.z = _xz_velocity.z
green mortar
#

I have the _xz portion out from velocity on line 44 and 45 and under the if node but after testing the current scene still nothing according to your screenshot I see equal sign next to set under else but on mine there is ("....) so do i take out the brackets and just put the equal sign

olive locust
jaunty river