@@andrewsneacker1256 I was new and I wanted to make a 3d camera rig similar to the Zelda games. I didn't know the spring arm existed I spent a long while making it but it was mostly for fun and to explore the engine. I made a video about it here. It's kind of old but it goes over my process. ua-cam.com/video/uVeZVHgXcSU/v-deo.html
When combining a capsule with a cylinder you can get a capsule with a edge peaking out. This way you have the smooth movement on slopes but still don't completely fall off platforms.
I ended up making my own collision shape in Blender that's a cylinder with shaved edges so you still slide but have a flatter service for standing on ledges and people's heads.
In trying to visualize the Collison body. Would it basically be like a pig in a blanket? A capsule that is inside a bigger cylinder with the top and bottom nubs poking put?
For anyone wondering how to make the character smoothly look at it's direction, check spherical linear interpolation out: # set this from a parent Rigid- or KinematicBody's script var direction = Vector3.FORWARD func _process(delta): direction.y = 0 global_transform.basis = smooth_look_at(global_transform, global_transform.origin - direction, delta) func smooth_look_at(t : Transform, dir, delta): return t.basis.slerp(t.looking_at(dir, Vector3.UP).basis, delta) Make sure to not do any scaling on the model you want to rotate. Ideally you have a Rigid- or KinematicBody with a Model node inside that you rotate around...
Made it a lot more simple. In the players script in this video I just changed rotation line "_model.rotation.y = look_direction.angle())" to "_model.rotation.y -= (_model.rotation.y - look_direction.angle())*delta*rotation_speed" where "rotation_speed" is a variable exported and placed with all other exports at the beginning. Would it be better?
I'm pretty sure the player controller shown in the preview here is tweaked way better in the code besides what's shown, besides having a fully animated player model of course. Encountered some weird bugs: -I manually adjusted the springarm to the neck height of my model but it's still on the floor. I know the camera at least works cause it's the proper springarm distance away. (Still not fixed) -I can't rotate the camera with any mouse movement. (Change func _unhandled_input to just _input) -My character moved in opposite directions than what they were supposed to for left and right. (Fixed by swapping left and right input names in code.) -The character likes to immediately reface north for some reason if jumping in place. The code for facing the mesh forward does not discern between just the horizontal vector and any direction of velocity taken. (Temporary fix by adding "var look_direction..." lines of code under "if is_on_floor():" so that the character at least keeps his rotation in the direction he jumped) (New Fix: As of 4.0.1 stable mono, "character bodies" now have better physics variable built into the default scripts. You can now generate a template script to call these variables for basic movement for you so you don't need to manually define _velocity from move_and_slide_with_snap! Character now rotates and stays properly with built in velocity variable for our look_direction variable!)
I dunno if you ever found a fix, but you can simply adjust the height of the camera by adding a vector3 to your player scene and doing addition to the translation(position). var camera_offset: Vector3 = Vector3(0, 2.5, 0) # the middle is Y so put your height offset in meters. Then in the line to set the translation (which is now called position) you do spring_arm.position = position + camera_offset. As for the _unhandled_input() every script can have an _unhandled_input and it will be called as long as no other nodes set the input as handled. If they are, that's causing your problem. I can't tell without actually looking at your code, but I used the _unhandled_input a lot as a hack to be able to press ESC and get pause menus and things to come up without having to code the input into a specific player or level scene.
@@lyghtkruz Thank you, this helps a lot. I might try changing my pause script first then since that seems simplest and it uses the regular _input() function. I also use G 3.5 so idk if that has some issues between G4 but my knowledge is still minimal.
@@lyghtkruz Thanks for the heads up. I'm still not sure how I'd set up translation scripts as I still don't know if I could code a respawn node for the player falling out of the world. Also since I got your attention, what do you think would be a good game object to attach the regular input function to?
I'm a newby just like many who are watching this video... Hey, don't give up! Watch this video everyday (not hard because it's a short one) and read the Godot Docs as well to learn more about all those things that are showed in the video. You'll see. Thank you again, GDQuest. Great tutorial.
Do you need to add a colission shape like this for every character? Surely there's a way to reuse the same one? How do you know what all these nodes and things you're adding are and what tey do? 1:07 How does the character have an idle animation already? 1:49 Where is all this code coming from!?!? gaaaaaahhhh I'm so overwhelmed
Very cool! Are you guys working on a course for Godot 4? I'm totally new to game development and after trying out Godot 4 alpha and seeing how fun it is, as opposed to Unreal 5 that's very overwhelming, I'm 100% set on making a 3D game like the one you show here.
I wish that I had found this video five months about when I first installed GODOT. It would have cleared up so many things that I have been googling for hours.
Quick question: Everything works perfectly fine except the character faces the complete opposite direction of where they're supposed to. Any idea what's going wrong? I have no idea what could've caused it but I did manage to "fix" it by adding 180 degrees in radians when I convert the look direction to radians
Took me a while to understand why my character would just face back to global angle 0°, specifically when there was vertical movement while I was doing no movement input... The solution was using a Vector2 for length(): instead of using _velocity directly, I created a Vector2 variable with _velocity x & z only instead.
So I was having problems with the camera not following/orbiting the kinematic body it and the spring arm was attached to. After pulling my hair out a while, I figured out it was b/c the kinematic body wasn't the root node. I tend to have a basic node as a root node(in this case, a spatial node), but that completely messed up the cam orbit. I always thought the base nodes worked more like folders, so I didn't think that was the thing messing it up.
Followed the instructions in the video exactly, _to the letter,_ and it barely works at all. You can only see the player when they jump for some inexplicable reason. Mouse input doesn't register at all so I had to rebind it to keyboard keys in 45 degree increments. The rotation of the character is reset when jumping, which I never found a fix for. Is this tutorial for a completely different version of Godot than the latest update or something?? Is there a demo to show this code even working correctly? Because the code as shown does NOT represent what actually happens on-screen.
I found a solution to the first issue. For me it was something like this: I could see the player but the camera would snap into the player when viewed at >45°. I had to change the collision layer for the player (the spring arm was colliding with the player and forcing the camera into the player).
Update: Found a fix to the position resetting: Line 34 ("if _velocity.length() > 0.2"). Change it to if Vector"(_velocity.z, _velocity.x).length() > 0.2: (if you stand still and jump your velocity length will be > 0.2 but since the rotation is based on x/z axis not y (up down) the rotation resets to default. Tbh I think the rotation should be solved differently in the first place (save it a variable or something, idk).
can someone explain to me how the springarm actually works ? for some reason it always keep my camera at the height of my model's feet ok, i figured it out. the issue was in the collision mask
I follow you step by step, but for me the camera is in front of my character, my movement is inverted and for some reason camera behave very strange on certain angles
This is great. I had a C++ class in college that i barely remember, and this feels like EXACTLY what i'm looking for to get going again and maybe actually learn something.
Line 10: 'onready var _spring_arm: SpringArm = $SpringArm' keeps giving me the error 'Unexpected "Identifier" in class body,' possibly due to the fact that there is a new default name for the SpringArm, which is SpringArm3D. How can I fix this?
Hi, I'm having an issue with the character rotation, where the character's rotation snaps back to its starting direction whenever I jump. Has anyone else had this same issue, and did you find a solution? EDIT: Solution (gives smooth rotation and keeps rotation consistent while jumping): if Vector2(_velocity.z, _velocity.x).length() > 0.2: var look_direction = Vector2(_velocity.z, _velocity.x) _model.rotation.y = lerp_angle(_model.rotation.y, look_direction.angle(), delta * rotation_speed)
question: I've been trying to adapt this to have the player speed up the longer you hold the button and to slow down once released. I've gotten it to "work", but the deceleration breaks as soon as you rotate the camera. It works as intended when the camera is in it's default position relative to the player, but as soon as you move it the player starts to shake and spin really fast in place until its speed returns to 0, any idea what could be going wrong?
The line "move_direction = move_direction.rotated(Vector3.UP, _spring_arm.rotation.y).normalized()" is resetting your movement vector based on the camera's rotation. I don't know how one would go about solving this, but that is definitely related to your issue! My first guess is try making a temporary variable that stores the "momentum" perse and re-apply it to the movement vector once the camera's rotation changes?
Great tutorial everything is working, but i am just sad that you didn't say how to implement the animation to this kind of movement. I made some stuff to my game including dmg system, moving platforms and other obstacles but I can't figure out those movement animations 😞
Lol having to do all these details in unity myself made me realise how much better godot is in regard to having basic things like these covered by default.
it would have been very helpful to start with "Here is how you add a character from a model" or at least link to some resources for that lol, it's all well and good to have a collision shape that matches your character, but it doesn't help me add my character.
This is a really important tutorial, I needed to do exactly this in my project and wasn't able to find any guide. Thankfully things ended up working out but it cost me a lot of time to figure everything out.
Please could you tell me what script does Godot handle and where to learn this language? I want to make a super simple video game, but I don't know anything about programming writing, but I can do everything in 2D art
Welcome to gamedev! Godot uses the gdscript programming language. It's very easy to learn, and a lot like the popular programming language Python. Since you have no programming experience, I'd personally recommend either waiting for the Learn to Code with Godot from Zero course to be finished, or to learn another language like Python. Then once you have the basics down, it should take you only a couple days to pick up gdscript.
The reason for this is because to learn programming, you need to learn 2 things: How computers understand programming (Functions, variables, etc.) and syntax. (Syntax is just the rules of a language) Most Godot tutorials are great about teaching the gdscript syntax part, but expect you to know the other part. The good news is, once you learn how computers understand code, it's much easier to pick up new languages!
@@-HyperX- and there is a third part: APIs. APIs are the functions that give you access to all the wonderful ready-made functionality in the engine, library or framework you are using. If you can already code in one language then GDScript is very easy to learn as the syntax is simple - the APIs are also something you need to learn next
Can someone help me pls??it just wont work...i try oder tutorial and it wont let me move in 2d i can move but in 3d no...btw camera works perfecly...sori for bad english
This is a really good tutorial. Would you be willing to go more in depth as to how spring arms work in a future video? I can't seem to get mine to move with the player.
when the input is recieved, instead of setting speed to a value set acceleration to a value (0 when the key isnt pressed). then change the velocity by the acceleration. you will also need a deceleration variable. change velocity by subtracting deceleration when the button isnt pressed, but if the velocity is less than the deceleration set velocity to 0 sorry for the bad explanation
The camera is stuck below the character, even if I move back and up the SpringArm, and even if I do the same to the Camera, it still displays from the feet of the character. What mistake have I made? Edit: Worked around that by using a Position3D instead. Now, the character rotates the opposite way, while everything else works perfectly, including the movement direction.
Hey guys, please help ! Me and my friend want to share our project beetween us to edit in godot, as both wants to manage the project. What can we do ???
I have no fucking idea what I'm writing but if it makes my character move, that's fine.... c++ is freakingly easier to read and comprehend than gdscript
this seems to more or less work fine for me, but i've run into an issue where if the player starts anywhere except at the center of the map and slightly below "ground" (like where the editor draws the grid, i don't know what else to call it), the camera breaks in some way or another? like if the player starts too high up the camera is stuck in/under the floor and if they're not in the center then the camera stays in the center without them and moves really weirdly. it's technically ignorable if i make every map with that in mind, but it's pretty annoying...if i decided i wanted so much as the player to start facing a different direction i'd have to rotate the entire map to accommodate that. i tried adding some code to fix this myself but it didn't seem to work...i figured the issue was basically the camera doesn't directly inherit the player's position so what i did was under "set_as_toplevel(true)" in the camera code i added "translation = _playerloc.translation" (with "_playerloc" there being a variable to refer to the kinematicbody node or the player spatial node, i tried both but neither did anything) idk if anyone has any ideas on what's up with this it'd be helpful...i'm surprised nobody else seems to have mentioned this problem? i'm 99.9% sure all my camera code is the same as the video, the only thing i added was something to zoom the camera in and out with the scroll wheel but i had this problem before i added that...i can deal with it if i have to but i'd rather just have the thing be like...normal
I don't know you figured it or not, for going slightly under ground check your collision shape position, try moving the player mesh and collision shape exactly centre of the workspace it fixed my camera issue
the camera partly worked basically it was able to be moved up and down but not left and right and every time I pressed W A S or D my capsule kind of just tilted can somebody please tell me why.
Haven't worked for me. Gives me an error that length() can't work with vectors makes sense,but why is it in tutorial tho?has it been working before and now stopped?
The player script didn't work for me when it was attached to the root of the player scene. But when I attached it to the player node in my level scene it worked.
I think the problem is that [ if _velocity.length() > 0.2: ] still triggers if only _velocity.y is greater than 0.2, so to fix it all you have to do is remove _velocity.y from the equation. I'd try either [ if (_velocity * Vector3(1, 0, 1)).length() > 0.2: ] or [ if Vector2(_velocity.x, _velocity.z).length() > 0.2: ] There's probably a better way of doing it though, I'm a near-total noob.
Best thing to do is to convert the velocity vector into a vector2 which - as EpicallyAverageDude suggested - takes Y out of the equation. Normalizing the vector basically scales each value of the vector (x,y and z) into a value between 0 and 1 and getting the length of that gives the average magnitude of that vector. The only values we care about for look direction is X and Z - the 2D vector representing direction in respect to the ground. So we convert the vector3 to vector2 by just ommitting the Y value and then checking the normalized length of that vector. var velocity2D = new Vector2(_velocity.x, _velocity.z) if velocity2D.normalized().length() > 0.2: # Do rotation Hope this helps :)
GDScript uses : to define variable type, for example var x : int is telling Godot that this variable is supposed to be a whole number and you can add the value later. When you set the value when defining the var you can type := or leave a blank space in between : = and Godot will figure out what type of data you are giving it and assign its type automatically
@@ralfwright just using = makes it a dynamic variable, which is slower and doesn't have the best autocompletion. Using := makes Godot infer the type, and it gets optimized for performance + better auto compete. It'll also now catch errors if you try to store something that isn't the right type into that variable
Silly question... How do I alter the height of the camera. I tried manually moving both the camera's node and then the spring arms node but the main XYZ is still the floor. can you help me?
How can I save a game with Godot. I am making a Drifting game and need to save the colors and specs of each vehicle. Will a res file work because I am planning on instancing the vehicles in the garage.
My caracter is not moving the camera works fine and the player rotates when movement inputs are pressed but it dosent move why pls help void: var move_direction := Vector3.ZERO move_direction.x = Input.get_action_strength("right") - Input.get_action_strength("left") move_direction.z = Input.get_action_strength("back") - Input.get_action_strength("forward") move_direction = move_direction.rotated(Vector3.UP, _spring_arm.rotation.y).normalized()
i have some questions, i am an absolute beginner and idk how to add a character to the game, is there anywhere i can get one from? is there any way to add a jetpack? and finally idk if i should use godot the only other thing ive used is scratch (for 3 years)
Check out our short about open source demos and assets. You can definitely get our 3D characters from our github repo. ua-cam.com/users/shortssqp98PGszkM And you can definitely use Godot. If you're still learning how to code, try the free app to Learn GDScript. You can find it on gdquest.com.
how do i add a model into godot? i cant make models so i download models i want to use but i cant use any of the downloaded models or add the models into blender to export them that way.
Check out CGDive's tutorial, "Blender to Godot: Rigged Character Workflow". I followed that tutorial besides this one and it covers everything about importing the model
i've noticed that in most of tutorials people use collision shapes based on primitives for their own character models. Is it a bad practice to just use auto generated collision shapes from the mesh in the engine ?
It's generally for performance reasons (and also because simpler generally means fewer sources of bugs). Simple convex shapes are much quicker to check. However, the old wisdom on performance is: don't bother unless you're noticing slowdowns. So keep using your full mesh collision shapes if they don't drop frames!
I carefully did everything this tutorial says, and nothing works properly. The camera have a weird rotation, when the character jumps he flies and the model faces anywhere. It does NOT work on Godot 3.5.1
Well this video was created a year ago using an older version of Godot... Some methods used have been changed... You can't follow this tutorial blindly and expect it to work unless you're using the same version they are. I assume they used Godot 3.3.4 in this video. And you wrote 'nothing works properly', what exactly was not working as intended? If you're looking for help you should comment the error and have people bugfix for you if you're too incompetent to do it yourself?🤷🏼♂
This works fantastically! Thank you so much. Is there a tutorial or fix that can help prevent my character running up slopes that should be to steep? When I encounter a wall with a slight angle, my character shoots up and over like a slingshot. Is there a way to restrict movement when confronted with step angles?
@@backofmyhouse I think what you're looking for is "stop_on_slope" and "floor_max-angle", based on the documentation for KinematicBody: move_and_slide_with_snap ( Vector3 linear_velocity, Vector3 snap, Vector3 up_direction=Vector3( 0, 0, 0 ), bool stop_on_slope=false, int max_slides=4, float floor_max_angle=0.785398, bool infinite_inertia=true )
hi there, please help me on script below move_direction = move_direction.rotated(Vector3.UP), _spring_arm.rotation.y).normalized() is in red highlighted which is not working 2:52
Understandable. As you're learning, you come across plenty of tutorials and videos that only end up teaching you that you're not quite there yet. But that's important info too. So you go one step back to find a starting point that's right for you.
📣📣 *UPDATE !!* GODOT 4 REMAKE now available: ua-cam.com/video/JlgZtOFMdfc/v-deo.html 📣📣
For Godot 4, I found that the .translation property was renamed to .position, and rotation_degrees is just rotation.
good info! additionally, set_as_toplevel(true) is now set_as_top_level(true)
Update: As of Godot Beta 4 v10,. they added back rotation_degrees
THANK YOU!!
Thank yoou!! 🤩
This should be pinned
Kinematic body has been changed to character body in Godot 4
Thank you!
tysm !!
tysm omg i'd be so lost without this
So do we just emit the parts related to snapping, or...?
You dropped this, King👑
I spent months setting up 3d camera. Had no idea spring arm existed. Would have saved me so much time.
how and why
@@andrewsneacker1256 I was new and I wanted to make a 3d camera rig similar to the Zelda games. I didn't know the spring arm existed I spent a long while making it but it was mostly for fun and to explore the engine. I made a video about it here. It's kind of old but it goes over my process. ua-cam.com/video/uVeZVHgXcSU/v-deo.html
Ha
@@AriaOrAriesf u
This comes like fallen from heaven, I've been trying for the past two days to accomplish exactly this. Thank you!
When combining a capsule with a cylinder you can get a capsule with a edge peaking out. This way you have the smooth movement on slopes but still don't completely fall off platforms.
That's genius
I ended up making my own collision shape in Blender that's a cylinder with shaved edges so you still slide but have a flatter service for standing on ledges and people's heads.
@@wolcamophone4783 That's also a good idea.
@@wolcamophone4783 And that’s why these communities are so useful. Simple idea but useful one! Thank you!
In trying to visualize the Collison body. Would it basically be like a pig in a blanket? A capsule that is inside a bigger cylinder with the top and bottom nubs poking put?
For anyone wondering how to make the character smoothly look at it's direction, check spherical linear interpolation out:
# set this from a parent Rigid- or KinematicBody's script
var direction = Vector3.FORWARD
func _process(delta):
direction.y = 0
global_transform.basis = smooth_look_at(global_transform, global_transform.origin - direction, delta)
func smooth_look_at(t : Transform, dir, delta):
return t.basis.slerp(t.looking_at(dir, Vector3.UP).basis, delta)
Make sure to not do any scaling on the model you want to rotate. Ideally you have a Rigid- or KinematicBody with a Model node inside that you rotate around...
Thank you 😭😭
Made it a lot more simple. In the players script in this video I just changed rotation line "_model.rotation.y = look_direction.angle())" to
"_model.rotation.y -= (_model.rotation.y - look_direction.angle())*delta*rotation_speed"
where "rotation_speed" is a variable exported and placed with all other exports at the beginning. Would it be better?
Oh, there was a mistake, the line should be : _model.rotation.y = lerp_angle(_model.rotation.y, look_direction.angle(), delta * rotation_speed)
@@konstantingolubev3822 ok
Thanks 👍
I'm pretty sure the player controller shown in the preview here is tweaked way better in the code besides what's shown, besides having a fully animated player model of course. Encountered some weird bugs:
-I manually adjusted the springarm to the neck height of my model but it's still on the floor. I know the camera at least works cause it's the proper springarm distance away. (Still not fixed)
-I can't rotate the camera with any mouse movement. (Change func _unhandled_input to just _input)
-My character moved in opposite directions than what they were supposed to for left and right. (Fixed by swapping left and right input names in code.)
-The character likes to immediately reface north for some reason if jumping in place. The code for facing the mesh forward does not discern between just the horizontal vector and any direction of velocity taken. (Temporary fix by adding "var look_direction..." lines of code under "if is_on_floor():" so that the character at least keeps his rotation in the direction he jumped) (New Fix: As of 4.0.1 stable mono, "character bodies" now have better physics variable built into the default scripts. You can now generate a template script to call these variables for basic movement for you so you don't need to manually define _velocity from move_and_slide_with_snap! Character now rotates and stays properly with built in velocity variable for our look_direction variable!)
Thank you :)
I dunno if you ever found a fix, but you can simply adjust the height of the camera by adding a vector3 to your player scene and doing addition to the translation(position). var camera_offset: Vector3 = Vector3(0, 2.5, 0) # the middle is Y so put your height offset in meters. Then in the line to set the translation (which is now called position) you do spring_arm.position = position + camera_offset. As for the _unhandled_input() every script can have an _unhandled_input and it will be called as long as no other nodes set the input as handled. If they are, that's causing your problem. I can't tell without actually looking at your code, but I used the _unhandled_input a lot as a hack to be able to press ESC and get pause menus and things to come up without having to code the input into a specific player or level scene.
@@lyghtkruz Thank you, this helps a lot. I might try changing my pause script first then since that seems simplest and it uses the regular _input() function. I also use G 3.5 so idk if that has some issues between G4 but my knowledge is still minimal.
@Wolcamophone oh, the translation is only position in godot 4. Sorry for any confusion. Been using 4.0 for a while now.
@@lyghtkruz Thanks for the heads up. I'm still not sure how I'd set up translation scripts as I still don't know if I could code a respawn node for the player falling out of the world.
Also since I got your attention, what do you think would be a good game object to attach the regular input function to?
I'm a newby just like many who are watching this video... Hey, don't give up! Watch this video everyday (not hard because it's a short one) and read the Godot Docs as well to learn more about all those things that are showed in the video. You'll see.
Thank you again, GDQuest. Great tutorial.
Excellent! Got me up and running right away. Thanks for this!
I'm so hyped I've subscribed to this channel! This is great content!!!
It really worked for me after I look and try some tutorials, yours is the one that worked. Owe you a lot.
Do you need to add a colission shape like this for every character? Surely there's a way to reuse the same one?
How do you know what all these nodes and things you're adding are and what tey do?
1:07 How does the character have an idle animation already?
1:49 Where is all this code coming from!?!?
gaaaaaahhhh I'm so overwhelmed
Very cool! Are you guys working on a course for Godot 4? I'm totally new to game development and after trying out Godot 4 alpha and seeing how fun it is, as opposed to Unreal 5 that's very overwhelming, I'm 100% set on making a 3D game like the one you show here.
I wish that I had found this video five months about when I first installed GODOT. It would have cleared up so many things that I have been googling for hours.
Quick question: Everything works perfectly fine except the character faces the complete opposite direction of where they're supposed to. Any idea what's going wrong?
I have no idea what could've caused it but I did manage to "fix" it by adding 180 degrees in radians when I convert the look direction to radians
I'm also having this issue, did you figure it out?
move and slide with snap is changed now to move and slide only, also im watching this and translating the api in my head into c# code
i'm new and do am stuck because of the change what should i do now
Took me a while to understand why my character would just face back to global angle 0°, specifically when there was vertical movement while I was doing no movement input... The solution was using a Vector2 for length(): instead of using _velocity directly, I created a Vector2 variable with _velocity x & z only instead.
I wish you would provide the complete code.
So I was having problems with the camera not following/orbiting the kinematic body it and the spring arm was attached to. After pulling my hair out a while, I figured out it was b/c the kinematic body wasn't the root node. I tend to have a basic node as a root node(in this case, a spatial node), but that completely messed up the cam orbit. I always thought the base nodes worked more like folders, so I didn't think that was the thing messing it up.
extends KinematicBody
export var speed:float = 2.0
export var jump_force:float = 30.0
export var gravity:float = 50.0
export(NodePath) onready var _spring_arm = get_node(_spring_arm) as SpringArm
var _velocity := Vector3.ZERO
var _snap_vector := Vector3.DOWN
onready var _model := $AstronautSkin as Spatial
func _physics_process(delta:float)->void:
var move_direction := Vector3.ZERO
move_direction.x = Input.get_action_strength("right") - Input.get_action_strength("left")
move_direction.z = Input.get_action_strength("back") - Input.get_action_strength("forward")
move_direction = move_direction.rotated(Vector3.UP, _spring_arm.rotation.y).normalized()
_velocity.x = move_direction.x * speed
_velocity.z = move_direction.z * speed
_velocity.y -= gravity * delta
var just_landed := is_on_floor() and _snap_vector == Vector3.ZERO
var is_jumping := is_on_floor() and Input.is_action_just_pressed("jump")
if is_jumping:
_velocity.y = jump_force
_snap_vector = Vector3.ZERO
elif just_landed:
_snap_vector = Vector3.DOWN
if Vector2(_velocity.z, _velocity.x).length() > 0.2:
var look_direction = Vector2(_velocity.z, _velocity.x)
_model.rotation.y = look_direction.angle()
_velocity = move_and_slide_with_snap(_velocity, _snap_vector, Vector3.UP, true)
pass
func _process(_delta)->void:
if _spring_arm != null:
_spring_arm.translation = translation
pass
extends SpringArm
export var mouse_sensitivity := 0.05
func _ready()->void:
set_as_toplevel(true)
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
pass
func _input(event)->void:
if event is InputEventMouseMotion:
rotation_degrees.x -= event.relative.y * mouse_sensitivity
rotation_degrees.x = clamp(rotation_degrees.x, -90.0, 30.0)
rotation_degrees.y -= event.relative.x * mouse_sensitivity
rotation_degrees.y = wrapf(rotation_degrees.y, 0.0, 360.0)
pass
Nice mate
Followed the instructions in the video exactly, _to the letter,_ and it barely works at all. You can only see the player when they jump for some inexplicable reason. Mouse input doesn't register at all so I had to rebind it to keyboard keys in 45 degree increments. The rotation of the character is reset when jumping, which I never found a fix for. Is this tutorial for a completely different version of Godot than the latest update or something?? Is there a demo to show this code even working correctly? Because the code as shown does NOT represent what actually happens on-screen.
I found a solution to the first issue. For me it was something like this: I could see the player but the camera would snap into the player when viewed at >45°. I had to change the collision layer for the player (the spring arm was colliding with the player and forcing the camera into the player).
Update: Found a fix to the position resetting: Line 34 ("if _velocity.length() > 0.2"). Change it to if Vector"(_velocity.z, _velocity.x).length() > 0.2: (if you stand still and jump your velocity length will be > 0.2 but since the rotation is based on x/z axis not y (up down) the rotation resets to default. Tbh I think the rotation should be solved differently in the first place (save it a variable or something, idk).
Tutoriel incroyable ! superbe vidéo merci beaucoup ça va me remotiver à utiliser Godot =)
can someone explain to me how the springarm actually works ? for some reason it always keep my camera at the height of my model's feet
ok, i figured it out. the issue was in the collision mask
I follow you step by step, but for me the camera is in front of my character,
my movement is inverted and for some reason camera behave very strange on certain angles
Fantastic tutorial. Do you have any plans for making a new one for Godot 4?
Is there an expanded version of this tutorial that actually explains what's going on or am I supposed to just type these things on faith?
Faith and works in diligently finding the meaning of those words
This is great. I had a C++ class in college that i barely remember, and this feels like EXACTLY what i'm looking for to get going again and maybe actually learn something.
Line 10:
'onready var _spring_arm: SpringArm = $SpringArm'
keeps giving me the error 'Unexpected "Identifier" in class body,' possibly due to the fact that there is a new default name for the SpringArm, which is SpringArm3D. How can I fix this?
Never mind, I fixed it! I am using Godot 4, and you now have to use @onready instead of just onready
Hi, I'm having an issue with the character rotation, where the character's rotation snaps back to its starting direction whenever I jump. Has anyone else had this same issue, and did you find a solution? EDIT: Solution (gives smooth rotation and keeps rotation consistent while jumping):
if Vector2(_velocity.z, _velocity.x).length() > 0.2:
var look_direction = Vector2(_velocity.z, _velocity.x)
_model.rotation.y = lerp_angle(_model.rotation.y, look_direction.angle(), delta * rotation_speed)
Thank you so much for this. I've spent like 6 hours on this already.
hey, that's very nice
thank, that is why i read the coments
Do you have a tutorial about making this cute 3d robot?
question: I've been trying to adapt this to have the player speed up the longer you hold the button and to slow down once released. I've gotten it to "work", but the deceleration breaks as soon as you rotate the camera. It works as intended when the camera is in it's default position relative to the player, but as soon as you move it the player starts to shake and spin really fast in place until its speed returns to 0, any idea what could be going wrong?
The line "move_direction = move_direction.rotated(Vector3.UP, _spring_arm.rotation.y).normalized()" is resetting your movement vector based on the camera's rotation.
I don't know how one would go about solving this, but that is definitely related to your issue! My first guess is try making a temporary variable that stores the "momentum" perse and re-apply it to the movement vector once the camera's rotation changes?
Great tutorial everything is working, but i am just sad that you didn't say how to implement the animation to this kind of movement. I made some stuff to my game including dmg system, moving platforms and other obstacles but I can't figure out those movement animations 😞
Please make one about animations, animationTree and state machine, how to implement this in player script
the camera is not woking
Lol having to do all these details in unity myself made me realise how much better godot is in regard to having basic things like these covered by default.
it would have been very helpful to start with "Here is how you add a character from a model" or at least link to some resources for that lol, it's all well and good to have a collision shape that matches your character, but it doesn't help me add my character.
emberlynn's voice brings me joy :)
Aw heck, thank you! 😊
This is a really important tutorial, I needed to do exactly this in my project and wasn't able to find any guide. Thankfully things ended up working out but it cost me a lot of time to figure everything out.
That's kinda the downside to picking Godot
2:52 Why do you multiply with delta? The physics process has a static frame rate (usually 60)
Best tutorial ever, thank you so much !
Please could you tell me what script does Godot handle and where to learn this language? I want to make a super simple video game, but I don't know anything about programming writing, but I can do everything in 2D art
Welcome to gamedev! Godot uses the gdscript programming language. It's very easy to learn, and a lot like the popular programming language Python. Since you have no programming experience, I'd personally recommend either waiting for the Learn to Code with Godot from Zero course to be finished, or to learn another language like Python. Then once you have the basics down, it should take you only a couple days to pick up gdscript.
The reason for this is because to learn programming, you need to learn 2 things: How computers understand programming (Functions, variables, etc.) and syntax. (Syntax is just the rules of a language) Most Godot tutorials are great about teaching the gdscript syntax part, but expect you to know the other part. The good news is, once you learn how computers understand code, it's much easier to pick up new languages!
@@-HyperX- and there is a third part: APIs.
APIs are the functions that give you access to all the wonderful ready-made functionality in the engine, library or framework you are using.
If you can already code in one language then GDScript is very easy to learn as the syntax is simple - the APIs are also something you need to learn next
Can someone help me pls??it just wont work...i try oder tutorial and it wont let me move in 2d i can move but in 3d no...btw camera works perfecly...sori for bad english
amazing tutorial
This is a really good tutorial. Would you be willing to go more in depth as to how spring arms work in a future video? I can't seem to get mine to move with the player.
Omg ty i was looking for new version tuturial you are life saver
In kinematic body, I don't have the option physics body do you know the solution for it
If yes please let me know
Could someone possibly explain how one might add acceleration to the character movement? Tried a few things that didn't seem to work and I'm at a loss
when the input is recieved, instead of setting speed to a value set acceleration to a value (0 when the key isnt pressed). then change the velocity by the acceleration. you will also need a deceleration variable. change velocity by subtracting deceleration when the button isnt pressed, but if the velocity is less than the deceleration set velocity to 0
sorry for the bad explanation
The camera is stuck below the character, even if I move back and up the SpringArm, and even if I do the same to the Camera, it still displays from the feet of the character. What mistake have I made?
Edit: Worked around that by using a Position3D instead. Now, the character rotates the opposite way, while everything else works perfectly, including the movement direction.
i really apreciate your help with dowloanding this software
Hey guys, please help ! Me and my friend want to share our project beetween us to edit in godot, as both wants to manage the project. What can we do ???
I love this tutorial! This is amazing, easy to understand and correctly use Godot :) Thank you 😍
Life saver, thank you so much!
I have no fucking idea what I'm writing but if it makes my character move, that's fine.... c++ is freakingly easier to read and comprehend than gdscript
What is the name of the 3D Player Model that is used in the video? Thank you!
did you found out?
how do you use the move_and_slide_with_snap on godot 4?
i have the same problem, let me knoe if you find it :/
@@HitCoder No luck here bud :(
@@kaduyeah found it yet?
@@a_a210 nop
this seems to more or less work fine for me, but i've run into an issue where if the player starts anywhere except at the center of the map and slightly below "ground" (like where the editor draws the grid, i don't know what else to call it), the camera breaks in some way or another? like if the player starts too high up the camera is stuck in/under the floor and if they're not in the center then the camera stays in the center without them and moves really weirdly. it's technically ignorable if i make every map with that in mind, but it's pretty annoying...if i decided i wanted so much as the player to start facing a different direction i'd have to rotate the entire map to accommodate that.
i tried adding some code to fix this myself but it didn't seem to work...i figured the issue was basically the camera doesn't directly inherit the player's position so what i did was under "set_as_toplevel(true)" in the camera code i added "translation = _playerloc.translation" (with "_playerloc" there being a variable to refer to the kinematicbody node or the player spatial node, i tried both but neither did anything)
idk if anyone has any ideas on what's up with this it'd be helpful...i'm surprised nobody else seems to have mentioned this problem? i'm 99.9% sure all my camera code is the same as the video, the only thing i added was something to zoom the camera in and out with the scroll wheel but i had this problem before i added that...i can deal with it if i have to but i'd rather just have the thing be like...normal
I don't know you figured it or not,
for going slightly under ground check your collision shape position, try moving the player mesh and collision shape exactly centre of the workspace it fixed my camera issue
Should’ve gone over character animation. Would’ve definitely saved me a headache while trying to get it right.
the camera partly worked basically it was able to be moved up and down but not left and right and every time I pressed W A S or D my capsule kind of just tilted can somebody please tell me why.
i love how u blur ur search history
Haven't worked for me.
Gives me an error that length() can't work with vectors
makes sense,but why is it in tutorial tho?has it been working before and now stopped?
I followed the tutorial using Godot 3.4 and noticed that my spring arm & its camera is fell to the floor. Anyone can help with this problem? Thank you
Simple Under
spring_arm.translation = translation
Add
spring_arm.translation.y = translation.y + 1.375
Rigid body -> (R) -> realistic
Kinematic body -> (K) -> Controll (c sounds at least like an k 😅)
The (Vector3.Up, _spring_arm.rotation.y) is not working for me. Is anybody else having this problem?
Yeah. I can't figure out what the problem is.
It's cool, but is it possible to make like so it will incline towards movement direction. I don't know how to say it but like realisticly
You can roate the capsule collider?! Take that, Unity!
The player script didn't work for me when it was attached to the root of the player scene.
But when I attached it to the player node in my level scene it worked.
Thank you for your awesome videos.
I think the problem is that [ if _velocity.length() > 0.2: ] still triggers if only _velocity.y is greater than 0.2, so to fix it all you have to do is remove _velocity.y from the equation. I'd try either [ if (_velocity * Vector3(1, 0, 1)).length() > 0.2: ] or [ if Vector2(_velocity.x, _velocity.z).length() > 0.2: ]
There's probably a better way of doing it though, I'm a near-total noob.
Best thing to do is to convert the velocity vector into a vector2 which - as EpicallyAverageDude suggested - takes Y out of the equation. Normalizing the vector basically scales each value of the vector (x,y and z) into a value between 0 and 1 and getting the length of that gives the average magnitude of that vector.
The only values we care about for look direction is X and Z - the 2D vector representing direction in respect to the ground. So we convert the vector3 to vector2 by just ommitting the Y value and then checking the normalized length of that vector.
var velocity2D = new Vector2(_velocity.x, _velocity.z)
if velocity2D.normalized().length() > 0.2:
# Do rotation
Hope this helps :)
I think export is @export in godot 4 for anyone new to it like me :)
Why do you put ":" before "=" when defining a variable?
GDScript uses : to define variable type, for example var x : int is telling Godot that this variable is supposed to be a whole number and you can add the value later. When you set the value when defining the var you can type := or leave a blank space in between : = and Godot will figure out what type of data you are giving it and assign its type automatically
@@noid3571 But doesn't = do the same? I come from python so sorry if I got something mixed up
@@ralfwright just using = makes it a dynamic variable, which is slower and doesn't have the best autocompletion. Using := makes Godot infer the type, and it gets optimized for performance + better auto compete. It'll also now catch errors if you try to store something that isn't the right type into that variable
@@dugtrioramen ah ok. Thanks! 👍
@@noid3571 Oh, thanks for the help!
Silly question... How do I alter the height of the camera.
I tried manually moving both the camera's node and then the spring arms node but the main XYZ is still the floor.
can you help me?
Is this scene and character available somewhere please? It reminds me of Astroneer. I'd love to follow along with the tutorial.
So, everything works...BUT. Why is my mouse spinning crazy when i move my mouse?
I could not get a mesh in because I didn't know how or where you got that character from.
why dosent this work?
export var speed := 7.0
export var jump_strength := 20.0
export var gravity := 50.0
in godot 4 you must use @export instead of just export, so:
@export var speed := 7.0
@export var jump_strength := 20.0
@export var gravity := 50.0
@@user-un2vb8mr6e thanks
How can I save a game with Godot. I am making a Drifting game and need to save the colors and specs of each vehicle.
Will a res file work because I am planning on instancing the vehicles in the garage.
how would I get the spring arm to move with the right stick on a controller rather than just the mouse?
KinematicBody doesn't exist when I try to add it??
It was renamed to CharacterBody3D in Godot4
Nice informative video as always thank you .i have a doubt how can i implement the same thing in 2d in godot4
when I put in move_direction it says unexpected token: move_direction, how do I fix that?
Will we ever see one of these micro tutorials for 3D character animation? Or is that too much to fit in to this kind of video format?
You'll find much better animation tutorials elsewhere. Here's an excellent animator and instructor: ua-cam.com/users/PierrickPicaut_P2DESIGN
@@Gdquest thanks for the response! I just mean as far as implementing them into finite state machines and such.
Hey uh, at line 24 of the first script godot detects it as an error and i dont know if it could brake my character
My caracter is not moving the camera works fine and the player rotates when movement inputs are pressed but it dosent move why pls help void:
var move_direction := Vector3.ZERO
move_direction.x = Input.get_action_strength("right") - Input.get_action_strength("left")
move_direction.z = Input.get_action_strength("back") - Input.get_action_strength("forward")
move_direction = move_direction.rotated(Vector3.UP, _spring_arm.rotation.y).normalized()
_velocity.x = move_direction.x * speed
_velocity.z = move_direction.z * speed
_velocity.y -= gravity * delta
var just_landed := is_on_floor() and _snap_vector == Vector3.ZERO
var is_jumping := is_on_floor() and Input.is_action_just_pressed("jump")
if is_jumping:
_velocity.y = jump_strenght
_snap_vector = Vector3.ZERO
elif just_landed:
_snap_vector = Vector3.DOWN
_velocity = move_and_slide_with_snap(_velocity, _snap_vector, Vector3.UP, true)
if _velocity.length() > 0.2:
var look_direction = Vector2(_velocity.z, _velocity.x)
_model.rotation.y = look_direction.angle()
func _process(_delta: float) -> void:
_spring_arm.translation = translation
is there any github page, it's hard to glance the code from video alone,
github would be nice
This is really useful until you try it and find that you need to call the functions. Where do I call them?
i have some questions, i am an absolute beginner and idk how to add a character to the game, is there anywhere i can get one from? is there any way to add a jetpack? and finally idk if i should use godot the only other thing ive used is scratch (for 3 years)
Check out our short about open source demos and assets. You can definitely get our 3D characters from our github repo.
ua-cam.com/users/shortssqp98PGszkM
And you can definitely use Godot. If you're still learning how to code, try the free app to Learn GDScript. You can find it on gdquest.com.
@@Gdquest thanks :) people have said gdscript is similar to python, and i know some python, so thats why i picked godot ( and its free)
Yo I wanted to back up the kickstart but the time ended today! How I can help I would love to get the lifetime Godot mega course
how do i add a model into godot? i cant make models so i download models i want to use but i cant use any of the downloaded models or add the models into blender to export them that way.
Check out CGDive's tutorial, "Blender to Godot: Rigged Character Workflow". I followed that tutorial besides this one and it covers everything about importing the model
BROOO thankyou so much, this really helped and the tutorial was really easy to use as well :)
it's great! thanks!
Can anyone help me on how to implement this in Godot 4 ?
Cant we have two different variables
Jump speed and jump height?
i've noticed that in most of tutorials people use collision shapes based on primitives for their own character models. Is it a bad practice to just use auto generated collision shapes from the mesh in the engine ?
It's generally for performance reasons (and also because simpler generally means fewer sources of bugs). Simple convex shapes are much quicker to check. However, the old wisdom on performance is: don't bother unless you're noticing slowdowns. So keep using your full mesh collision shapes if they don't drop frames!
I carefully did everything this tutorial says, and nothing works properly. The camera have a weird rotation, when the character jumps he flies and the model faces anywhere. It does NOT work on Godot 3.5.1
Well this video was created a year ago using an older version of Godot... Some methods used have been changed... You can't follow this tutorial blindly and expect it to work unless you're using the same version they are. I assume they used Godot 3.3.4 in this video.
And you wrote 'nothing works properly', what exactly was not working as intended? If you're looking for help you should comment the error and have people bugfix for you if you're too incompetent to do it yourself?🤷🏼♂
im on 3.5.1 and it works fine
@@just.tiramisu Me too but I had to adjust the code obviously due to deprecations. This code doesn't transfer directly to 3.5.1
This works fantastically! Thank you so much.
Is there a tutorial or fix that can help prevent my character running up slopes that should be to steep?
When I encounter a wall with a slight angle, my character shoots up and over like a slingshot.
Is there a way to restrict movement when confronted with step angles?
I'm having the same issue, I think it has something to do with move_and_slide()
@@da_roachdogjr yeah, but I'm using move_and_slide_with_snap(). It's this an issue with both?
@@backofmyhouse I think what you're looking for is "stop_on_slope" and "floor_max-angle", based on the documentation for KinematicBody:
move_and_slide_with_snap ( Vector3 linear_velocity, Vector3 snap, Vector3 up_direction=Vector3( 0, 0, 0 ), bool stop_on_slope=false, int max_slides=4, float floor_max_angle=0.785398, bool infinite_inertia=true )
You pro man gdquest world 1st godot teacher
İm no english
Where did you get that model? That's kind of cool
hi there,
please help me on script below
move_direction = move_direction.rotated(Vector3.UP), _spring_arm.rotation.y).normalized()
is in red highlighted which is not working
2:52
move_direction = move_direction.rotated(Vector3.UP, _spring_arm.rotation.y).normalized()
After Vector3.UP you put ) when it is not needed.
@@metaj9278 thank you👍🏻
As a begginner,
I have absolutly NO IDEA what any of this means lol
Understandable. As you're learning, you come across plenty of tutorials and videos that only end up teaching you that you're not quite there yet. But that's important info too. So you go one step back to find a starting point that's right for you.
For some reason, when I type var just_landed: = is_on_floor() and _snap_Vector == Vector3.ZERO , it says theres an error