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
#Need help with character walking in current scene
1 messages · Page 1 of 1 (latest)
You'll need to share your code if you want us to help you
your if is always true, so you're not applying velocity to xz.
how to do I fix it?
I don't see how? When Vector2 is cast to a bool, a 0,0 will return false, and anything else will return true.
So the if will be true if any input is being given.
that is true a Vector3 will be cast to false if it has no movement, but ins't that the opposite that you want?
De-indent 44-46
you mean get rid of Velocity.x and Velocity. Y on 45 and 46?
no just de ident it
No
Lower indentation
make it part of the parent identantion
Shift+tab
basically the if there is just setting xz to the velocity if movement is false, instead of setting _xz var and seeting velocity later.
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
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.
so just _xz_velocity = ... instead of what I have with the move_toward something something
?
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
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
It sounds like you would benefit from learning some coding fundamentals first https://docs.godotengine.org/en/stable/getting_started/introduction/learn_to_code_with_gdscript.html
Godot Engine documentation
In Godot, you can write code using the GDScript and C# programming languages. If you are new to programming, we recommend starting with GDScript because we designed it to be simpler than all-purpos...
Screenshot please so we can verify