Godot 4: 3D Character Controller
Вставка
- Опубліковано 14 жов 2024
- In this series of videos, we look at how to import, setup, and use 3D models in Godot, whether you downloaded them or created them yourself.
You can download the art packs we're using from Kay Lousberg at itch.io:
kaylousberg.it...
Text version and link to code:
kidscancode.or...
Want to learn Godot 4? Check out my new book, Godot 4 Game Development Projects.
Available now! amzn.to/3qcOZ4E
Support me on Patreon: / kidscancode
Your last 3 videos are amazing! Reignited my interest in game dev! Thank you and I hope you continue to make more guides like these!
Thank you!!! I was having a lot of trouble understanding how to correctly rotate the camera towards the direction of movement in Godot 4 using a CharacterBody3D. You made it very clear and simple, nicely done!
Happy to see you back! Thanks for the great content as usual.
Yesss. I bought also kaykit extended edition of the characters and more of them. So ready to do my RPG in godot
This is my favourite channel!
P.S can you make a tutorial for a plane simulator, but in godot 4.1 or 4 please
Wish you would keep going with the series, good job
So cool, glad you are back. Any chance you can do a follow up for game pad controls? Converting the mouse to thumbstick is always confusing.
Thank you so much!!
For some reason my Godot wasn't able to reliably grab the default gravity variable, so I added 9.8 to fall back on:
var gravity = ProjectSettings.get_setting("physics/3D/default_gravity", 9.8)
I have a lot to learn, your videos are really helpful!
What a great series! Thank you so much! 🙏🙏🙏
When's the next episode coming?
Finally! Thank you!
Thanks for the video lesson, is there a sequel on UA-cam or somewhere else, or is this lesson frozen?
I learned python from you, now its time to learn godot from you.
I like your work sir, it is awesome
I'm hoping you're planning on still making more videos, they are a great help!
no new procedural generation tuts? loves the 3 vids btw
Brilliant! Thank you so much!
there's this part like 3 videos ago when you're first importing the knight where you were like "yeah and like some of these animations need to be looping like the idle and walking ones and whatever okay moving on" that i feel like you should have been clearer about. As soon as I saw it I was like "I'm definitely gong to miss one of those and it's definitely going to screw me later" and so here i am, screwed, obviously.
Basically, how do I set the "Jump_Idle" animation to be looping from this point in the process?
Last time I tried reimporting the knight it wiped the entire animation tree out of existence and plus you never actually said what the correct settings were in the first place so I'd just be guessing again.
For you and anyone else that reads this. You need to reimport the animations and set the loop mode to Linear. Click on the Import tab (top right) then select your resource (Knight.glb) you may have to click on another file first and then back to it. Then in the Import screen click Advanced and a new window will open up. Scroll down until you find your animations and all the ones that you want to loop click on them and then in the top right where it says Loop Mode set it to Linear. Once done for all animations that you want to loop, click Reimport and you are done.
Thank you
Hi! Great tuotrial! One question: How I could blend the attack and walking animation, so when I walk and attack the upper body plays the attack animation and lower plays walking animation? I've tried with BlendTree but it didn't behaved very well...Thanks!
In BlendTree, you can use a Blend2 or Sub2 which have a filters list, where you can choose which bones you want to use.
I was looking for this but I cant figure how to do it exactly. Can you elaborate please ? Thank you so much
@@Kidscancode
I have set up my animation tree, but now I want my idle/walk animations to loop. Is there a way to set this up on the animation tree? I have the animations set to loop in the Animation tab, but they aren't looping. Any tips?
Great tutorial man! Hope you can also create a virtual joystick for mobile related to this! Thanks!
So cool, thank you very much. Looking forward the next videos.
if only you knew...
@@EverythingCoding29 What happened?
Hi, great tutorial, very clear. I am just having trouble with the model.rotation.y. when I have this
if velocity.length() > 1.0:
model.rotation.y = lerp_angle(model.rotation.y, spring_arm.rotation.y, rotation_speed * delta)
it's working, but my whole character flips 180 and then works. Im not sure exactly is happening
Idk if you already fixed it but you may have rotated the Rig node 180 degrees, but is the Skeleton 3D that must be rotated 180 degrees. Just reset Rig rotations and apply 180 degrees to the Skeleton 3D.
@@matzi-dev Hi, I've had the same problem and resetting the rotation of the entire model and rig didn't work. What did work, was to put the velocity.length() in the negative. So, it looks like this:
if -velocity.length() > 1.0:
model.rotation.y = lerp_angle(model.rotation.y, spring_arm.rotation.y, rotation_speed * delta)
I don't know why though!
Maybe it helps someone else in the future! :)
Any chance you can create a video with mobile controls or explain how to get them working?
I suppose, but there's really no difference to the character controller. The movement of the character is the same, the only difference is what produces the input action/event. A screen tap is the same as a mouse click, for example, so click-to-move and tap-to-move are the same thing.
Is it better to have all your planned animations for the character done before starting controller or is it easy enough to just keep adding animations as you go?
That's a design question more than a controller question. You should already know what you want your game to play like before even construction. List all the actions you want the character to be able to do (ie walk, run, jump, roll, attack, dodge, block, etc). Then you can make your character and their animations. What you set up in Godot is merely what key presses (or console controller buttons) will activate which action.
Everything is working except sometimes I have to click the left mouse button a couple of times before it performs the attack animation. How would I fix that?
Amazing thank you
Getting an error. The error is "Invalid get index 'transform' (on base: 'null instance')." It has a problem with a line of code under the function "func get_move_input(delta):" it doesn't like the line "var vl = velocity * model.transform.basis".
Any ideas why?
Theres a little delay when you hit the space button and start jumping animation(player is already on air when animation starts). Wich is the best way to fix this?
I'm not understanding the script keeps telling me "get_move_input" not found in base self
I really like 2D games, but 3D games seems to be more easy to do because you don't need to make sprites for every state in every angle.
Animation can be even more challenging than drawing sprites.
animations take wayyy more time than drawing sprites, especially when pixel art is used in 2D. Collision tests can be more tricky too.
In 2D there are only few select angles, but in 3D you have to make the animation look good from all possible angles.
thank you so much! too bad there are no more tutorials
so whenever i start the game and move around, the camera turns the the right of my screen instead of forward in the camera direction how do i fix this?
does anybody have the complete scene file for the knight? for some reason mine isnt working, and i cant figure out where the problem is.
How would one adjust this code if they don't currently have an anim_tree setup?
Currently running into an issue where after moving the camera even a little bit, strafing left and right or forward and back moves me in sort of an ellipse. But this doesn't happen if I run the scene with the mouse outside of the window. Strange.
My player isn't turning in the directions of movements and only idle animation is playing when moving. Interestingly all the attack ones work fine. The jumping works but turns to face forward if I'm rotated at all (though it has a little bounce/hop at the end??). They all work in Animation Tree preview as expected. No errors or debug log errors. I think I have all the code correct, but without a place to check the code, I'm stuck. I started with the text tutorial but it isn't clear where to add a lot of the code. In the video, I paused at all the script frames and checked, and I now have the lines placed correctly according to this video. It must have to do with Rotation and calling the 2D Blendspace for Idle/Walk/Run? What am I missing?
Here's my code for that part:
func get_move_input(delta):
var vy = velocity.y
velocity.y = 0
var input = Input.get_vector("left", "right", "forward", "backward")
var dir = Vector3(input.x, 0, input.y).rotated(Vector3.UP, spring_arm.rotation.y)
velocity = lerp(velocity, dir * speed, acceleration * delta)
var vl = velocity * model.transform.basis
anim_tree.set("parameters/Locomotion/blend_position", Vector2(vl.x, -vl.z) / speed)
velocity.y = vy
func _unhandled_input(event):
if event is InputEventMouseMotion:
spring_arm.rotation.x -= event.relative.y * mouse_sensitivity
spring_arm.rotation_degrees.x = clamp(spring_arm.rotation_degrees.x, -5.0, 5.0)
spring_arm.rotation.y -= event.relative.x * mouse_sensitivity
at spring_arm.rotation_degrees.x = clamp(spring_arm.rotation_degrees.x, -5.0, 5.0)
it should be spring_arm.rotation_degrees.x = clamp(spring_arm.rotation_degrees.x, -90.0, 30.0)
I'm getting an error when using travel on the animationtree to get to the jump idle animation. Any idea what could cause it?
The error: "Invalid call. Nonexistent function 'travel' in base 'AnimationTree'."
That's because you're calling it on the wrong object. 'travel' is a method of the AnimationNodeStateMachinePlayback, not of the AnimationTree itself. You should be calling it on the object you got with `$AnimationTree.get("parameters/playback"), as done in the example.
You can also see the docs for further details: docs.godotengine.org/en/stable/tutorials/animation/animation_tree.html#state-machine-travel
@@Kidscancode Ah I see what I did wrong. Also accidentally left an extra slash in the string parameter for the state machine.
Thank you very much!
Good to see you back sir! Some feedback about your mic sound: there is some boominess in the low freqs (maybe your room doesn't have much acoustic treatment or too close to the mic?). Maybe you could add a high pass filter from 0 to 80-100 dbs, or raise a few dbs on the high freqs. A mild compression may help too. Hope it helps.
Please enumerate
The videos of this series it pretty hard to follow them in order
Help? Keep getting the error "Invalid get index 'rotation' (on base: 'SpringArm3D'). Referring to a line of code under the function _unhandled_input(event):, the line of code it doesn't like is "spring_arm.rotation.x -= event.relative.y * mouse_sensitivity".
Any idea why? Could it have something to do with the version I'm in? Am in 4.2.2
EDIT: FIXED.
Had a somewhere that needed a comma, and another that needed an equals sign
its probably because they dont coincide
make sure you have the code for spring arm in the variables section
so it should be
var spring_arm_3d = “what ever you have”
so when you write it in the code for the camera movement make sure the variable you set spring_arm_3d is spelled the same through out the code
@@THEDEVBOIS I wish it was, unfortunately all is well on the side of spelling... thank you for trying though, might try a simpler camera movement code, but fingers cross the comment gets seen by the channel
Hey there. After a quick look on Google, it might be because you've placed that line in a part where it should not be. Or maybe you used @export instead of @onready. Don't be afraid to look up those kind of errors on Google, they usually have good answers :) Good luck!
@@redelixir9384 Hii, thanks for the advice & stuff. Unfortunately changing the mouse sensitivity from "@export" to "@onready" caused a separate error, plus an one. And I've had a peak, the line of code is in the same place in the video. Thanks for trying anyway, always nice to get a reply :) I'll keep tweaking, and try searching about the web as you suggest. Thanks again
Can you port your godot 3 projects to godot 4
im having a small problem and i dont know what it is the system wants
on the
if velocity.lenght() > 1.0:
if i have 1 indent on the if statement and 2 indents on the next code with “model” i get this error:
cannot find property “lenght” on base “Vector3”
when i have 1 indent on the if statement and 1 indent on the model code i get an error saying i need an indent??? even though i already have one💀
but when i have no indent on the if statement and 1 indent on the model code i get 3 errors
1. unexpected if statement in class body
2.unexpected indent in class body
3. expected end of file
like bru i already tried 15 hundred ways and idk what it wants any help
Hi there, hope this helps. It's a spelling error of the word 'lenght' . I know this because I made the same error :') It's spelled 'length' , the 'th' like you'd say 'the sixth' for example. Good luck! :)
@@redelixir9384 i figured it out awhile back now uh days im trying to figure out how a shooting mechanism works and for some reason its actually hard😂😂 its harder than figuring out how to make my player crouch.
@@THEDEVBOIS Oh shoot, came in late. Oops! Maybe it will help others in the future xD Oh. Man.... I haven't even started on the shooting part... Oh well. One step at a day! Good luck to you though. I'm dreading that part now :') *sigh* more programming :(((((
@@THEDEVBOIS Btw, did you happen to have a problem with the animations not triggering, more specifically the 'Jump_Idle' one? I mean, the jumping animation works at about 10% of the time..
@@redelixir9384lmao ur all good😂 and the jumping was working for me perfectly if your having issues with the jumping double check the arrows that go into the next animation. because i faced an issue where i jumped once and it worked but when i jumped again it was in a constant jump loop. i fixed it by double checking the arrows that go into the next animations and i also looped the jump animations which i shouldnt have. the only thing that should be looped is the jump idle.
If you miss just the right steps, you get a Jamiroquai video.
What about ai?
nothing in this tutorial works except making the animations
Bro the script is not working on mine laptop
I had the same problem. Changing
func _unhandled_input(event): to func _input(event): fixed it. (not sure if this helps your problem)
bro make control for android plz
Make a tutorial for a star wars game