Currently trying to make a Petscop-like game (2.5D is the word I believe) for a horror unfiction series. However, while I can implement sprites both static and animated, I cannot get the basic movement of the character to work. I’ve tried several different codes from various tutorials online but nothing seems to be working.
I’m still very raw when it comes to coding overall and I’m mostly a visual learner because of that. Any help is greatly appreciated.
Feel free to share your code so we can help you find what’s wrong with it.
Oh thank you!!
It’s basically the default code that comes with the characterbody
You’re not calling
move_and_slide() within physics_process. Make sure you call it to actually apply the velocity.
Even with this in it still won’t move
And you’re not getting any errors?
Also, where you call normalized, be careful about normalizing vectors that can have all-zero components, which this one can. Reason being, vectors are normalized by dividing it by their magnitudes to produce a unit vector (vector with a magnitude of 1), but if the magnitude is 0 and you divide by 0, you’re producing NaN values.
I see. This is the template default code that Godot provides so i dont know much about what else to add or take away from it
You’re not getting any errors?
As far as I could tell, your code looks like it should work. If you tried a bunch of different things from a lot of different tutorials and you’re getting no errors, maybe it’s not an issue of code.
Some other things to check:
- Make sure your script is attached to a CharacterBody3D node.
- Make sure you’re running a scene that holds the player and not just a player scene independently.
- Make sure the arguments you’re passing into get_vector are defined in the project input map.
Some things we usually do during the debugging process which are really helpful for finding bugs is either using breakpoints or print statements to make sure the code is reaching those places when we expect, and to check the values of variables like
velocity. If you can’t figure it out by staring at your code, try to collect information and print things.
Still not working. I’m frankly at a loss. Thank you for helping still!
Is it possible that you have a camera that moves with the character, thus making it look like the character is not moving?
I’ve tried that but the problem is that i put physical points to show movement and the character still appears stagnant.
Have you tried printing velocity in physics process like I suggested? What values does it print when you use the input keys, if it prints at all?
Nothing at all. It’s as though the code is there for decoration and nothing else
That’s very helpful for narrowing down the error. Some possibilities:
- Again, make sure the script is attached to a node
- Check your output for errors. I know I’ve asked for errors these past few messages but you didn’t confirm whether you had any or not.
- Make sure your scene tree isn’t paused anywhere.
- Make sure the CharacterBody3D process_mode isn’t set to when paused or something.
Another thing: where are you printing? In a conditional (if direction)? If so, try another print outside the conditional, like right before you call move_and_slide.
I apologize for being difficult. I really am. I’ve tried various methods and even with changes there are no inherent errors that show up.
The code works perfectly fine and yet im wondering if the 3d sprite might have something to do with it.
That’s alright, debugging is a process of gathering information and deducting the problem. Try my suggestion with a print statement right before calling move_and_slide. It’s also easier to help you when you show your code after each change.
Another possibility is if your Sprite isn’t a descendant of your CharacterBody3D, so make sure it’s a descendant and not a sibling or parent. Otherwise the Sprite will not move with it.
It is easier to determine the error, however, if you follow the debug process with printing. There are too many possible reasons so without collecting more info, the best we can do is guess.