Godot for Game Developers: A starting guide ! (C#)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello and welcome in this new video tutorial about the good organ engine my goal of this tutorial is to give you a quick guide in order to transition from another engines such as a unity or inwe'll to this 2d and 3d open-source game engine which is godo my goal with this tutorial is not to show you everything because you are not going to be able to do this in one video but I'm going to target people that already know their way around game development basically so if you already have made a game if you already have made a game using for instance unity or and will and you are familiar with any programming language you are going to catch up in this video so but if you're a beginner I highly recommend you to look around for other tutorials because this is not what I want to do with basically this video so let's get started once you've created your project in god oh by the way I'm using the c-sharp version of Google which is called the mono version you can download it in the description I'm going to provide a link and we are going to use so the C sharp programming language which is a very very familiar to unity people unity developers and we are going to learn about the things that you will have to learn if you want to make again basically in any engine we are going to learn about how to compose a scene use the different nodes that are available in Godot we are going to learn about transform we are going to learn about the math where are the the the math function that we're used to in other engines such as looping such as dot products and etc we are going to learn about how this engine deals with rotations we are going to learn about shaders a bit we are going to learn about user interface so basically I'm going to give you different bricks like Lego bricks if you want in order to have a quick start with this engine if you are already an experienced Kindle or even if you are basically a game developer so let's get started once you've created your own projects it should be very easy if you're basically following the the few steps that the engine is going to give you at the beginning you have a basically like the unity hub you can create a project once you've created the project it create you can edit it and you should be prompt with an editor like this okay so in the middle of the editor by default you have the 3d viewport and you can rotate around using your middle mouse button like this if you want to pan you can use the shift key plus the middle mouse button if you want to zoom in and out you can use your mouse wheel and if you want to move in different predefined views you can use the one key in order to go in the front view the seven key in order to go in the top view the three key in order to go in the side right view and if you press the 5 key in the middle of your numpad you're going to be able to toggle on or off perspective those are the shortcuts from blender so if you're familiar with window you will be at home here okay so of course you can change those shortcuts so in the editor editor settings if you go in the shortcuts tab you will be able to find all the shortcuts of godo and you're probably going to see let's type front view you can see it's the keypad so numpad 1 key and your you will be able to change all the shortcuts if you're very picky about that but as I'm a blender user it's really feeling great there okay so this is the 3d viewport and as you can see on the top bar here you have different options you have the 2d view which gives you the ability to edit 2d stuff such as sprites user into face components and this is really great because godo separates 2d 2d things and 3d things basically in unity when you edit for instance canvas you will see the canvas floating in the 3d view port and honestly this is quite a bit weird if you are coming from order engine the Hinton unity but in Godot it separates things pretty well moreover if you want to do a full to the game without using 3d stuff go dog won't embed the 3d part of the engine so that's pretty cool one or the tab that you have is the scripting integrated development text editor but if you don't want to use it and we are not going to use it because we are going to use C sharp and we will need a more professional environment to develop with this language you can use it but honestly I'm really using it and finally you have the asset lip which is a bit it's it's like a marketplace where you have projects that you can download and explore and even take some part of them in order to put them in your own projects so as you can see the vast majority of them are under the MIT license which is very free and open so we are going to go back in the 3d viewport and now we are going to learn more about how the synth we work in works in god so like many engine godo as a way to represent objects visually and also create a hierarchy of nodes so in unity for instance you have a scene which is composed of different game objects and on those game objects you have components it's not that different in Godot you have different nodes in Godot so let's create for instance a 3d scene node and with this node which is a spatial node a spatial is basically a 3d transform you can see that you can use the gizmos in order to change the location of the skismo and you can also see that when you select a node you have an inspector there like in G you have the inspector and like in unreal in the blueprint panel you have the different properties of the currently selected node component I should say so here you can see that you have the transform with translation rotation scale but you also have the matrix the world matrix of this node that you can edit but you don't have any place in order to drag components so basically that's where guru and energy is different it's not component based it's node based meaning that if you want to add another node you will have or another behavior and she'll say you you can add it as a child of another node so here for instance you have the spatial and we are going to add a child of this node by clicking on the plus button here or by pressing the ctrl a shortcut and here you can see that your access to all the different nodes that are part of this engine and if you are a programmer you will be at home here because it's using an oriented object an object oriented programming mindset basically as you can see the spatial is the root of the 3d but it inherits from node and as you can see inside a special you have all the nodes that inherits from the spatial so 3d nodes so let's take for instance a camera here and inside the camera you can see that you have different types of camera that innervates one can edit in here it's from spatial data now it's one node so it's pretty easy to understand it's like in unreal where you have actors etc and you have bones that innovate in the end from actors etc so here in this case we are going to select for instance a camera and we are going to create and because I've selected I've selected the spatial node you can see that it's added as a child of this node so now if I want to add another child of the spatial I need to select the spatial press ctrl-a and now I can let's say add a mesh to my scene so I'm going to search directly for mesh as you can see it filters out what I can have and I'm going to set the mesh instance and you can see that the mesh instance is now parent parented to the spatial okay if I want to change the parenting of this node I can select it and drag it on top of the camera now when I'm moving the camera as you can see I'm also moving the mesh instance so it's not it's not visible here because we didn't attach any mesh there but the mesh will be soon filled with properties that we are going to add so I'm going to unparent the mesh instance from the camera and add it back to the spatial but as you can see this is the only option that I have I cannot put the mesh instance on the top because for every scene 3 you need to have a root node so in this case the spatial is the first note that I've added and it's considered to be at the root so I can select the mesh instance I cannot like put it on top I can't change it but if I want I can say to go to now this machine stance is going to be the root so in order to do this I'm going to right click and I'm going to say we make scene root ok so once I've done this you can see that now the mesh instance is considered as the root node and you can see that the hierarchy didn't change here the camera is still attached to the spatial but now the spatial has no other way to be floating there it should be a child of the root node ok so let's go back I'm going to take the spatial back and I'm going to make it at the scene root and I'm back to where I was so now we are going to select the mesh instance node and we are going to add a mesh to it so as you can see here I have a field that I can change because of this type but as you can see here you have all the the hierarchy the inheritance of the different nodes that a mesh instance is made of so as you can see a meshes instance is a geometry instance that is a visual instance that is a spatial that is a node ok so now in the property of the mesh we are going to add a new mesh and what's cool about the girdle editor is that you have procedural basic primitives so we are going to add for instance a cube and as you can see I know I now have a resource in this property which is a cube and if I click on the new resource you can see that I have properties again for this resource so here you can see that yeah that I have the size of my cube so let's make it 1 1 1 I have the subdivision with height and depth of the cube so now my cube has only one quad per face purpose yes and here in the three dots three dots menu I can change my display view to wireframe for instance and you can see that the wireframe is like this and if I want to I can change the number of subdivisions let's add more subdivisions for instance to this cube and you can see that instantly Godot is giving me a new cube with more subdivisions you can also add a material in this case we are not going to do this but I'm going to first go back to the display normal view ok so as you can see now I have a mesh instance and this mesh instance I'm going to to push it on the z axis like this in order to make it visible from this camera and now what I'm left to do with as I can run the game so I'm going to click on this play button but Godot is going to tell me ok you are going to and something but what do you want to run which seem do you want to run and I'm going to first save the sins I'm going to save it like this I'm going to call it remains in Princeton's and godo is going to launch the key this is where unity people will be very disappointed because the build is loosely and very loosely linked with the editor when you are running a game in then in sorry in god oh you are actually running the true game you're running the build in unity the game is being executed inside the editor which is not the case in goda this has some advantages and of course from a designer point of view this is also a lot of drawbacks so but one thing that is still there in Godot is that you can still move objects around and Godot will try to update them so you can see that here I've moved to transform and the cubism is moving but you cannot do a lot of things I will say from a designer point of view such as if you are making procedural measures it will be a bit painful to not see your mesh and view it as a preview in the editor but again this is something that you can like find some ways around this but yes that's a big difference from unity or even in real okay so now that we've launched the game you can see that I've moved my cube but one cool thing is that if I'm closing the game the cube is still there so everything that I'm going to change in the editor will be still available when I rerun my game the second time I'm running the project you can see that Kudo is telling me that I need to select the main theme that I want to launch so I'm going to select the scene that is going to be the roots in of my projects so main scene the t SC t SC n yes okay so now my cube is still there as I've moved it there and now I can continue to work on our projects okay so the next thing that we are going to add is a light so you can see that we have a special which is going to be due again it's the root of our scene I can change it to be the root let's call it root or root or my scene for instance my scene and this node is a special node but if I want I can also on-the-fly change the type of my nodes so in this case let's say that I don't want my seem to be a special but I want my seem to be just a node so the top the the base class for every nodes I can right click and say change type and you can see that now Godot is asking me the new type that I want to make this node the the type of the that I want to change sorry that I want to change too so I'm going to select node and I'm going to say change and now you can see that now the icon changes and now it's a simple node and it's not a problem because godo in the 3d section will still see the 3d nodes so in this case you can see that I still have a camera I still have a mesh instance and I can still run the game so if I'm running the game I'm still having my camera I still have my cube and I still I still can launch my game okay I'm I can also select my camera and here when go to recognize that it's a camera you can select this icon in order to go through the camera view and this is quite useful if you don't want to launch the game and just see a point of view and one thing that you can do too is that you can split this view into so we can go in perspective here and you also go to hmm sorry it's not there it's not in the Indus bana lots in this panel you can select view and you can split it like this it's a bit like in blender so here I'm going to split it in two viewports horizontally like this and I'm going to have to viewport two viewports and here if I'm selecting my camera I can go in the preview mode here and I can still have my view here so that that's a pretty cool thing to note because you can steal a place your camera's the way you want and again from a designer point of view it's pretty cool as you can see because I've changed my scene to the root node to a simple node I don't have the the gizmos for the camera so I'm going to change back this node to a special and I can select my camera no no I think it's a bug so I'm going to delete my camera and I'm going to add it back as a camera sometimes things happens like this okay so now I have the gizmos back one thing to note is that in Godot you have a lot of tools like this using this small dot you can change the way some objects interacts with with the scene in this case I'm going to just change the field of view of the camera and as you can see this tool is linked to this property on the in the inspector so here I can still have access to the same feature okay so one thing that I'm going to do now is I'm going to scale my cube so in order to scale a cube I can access the scale transformation gizmo by pressing the Alt key and I'm going to flatten it flatten my cube I'm going to scale scale it on X I'm going to scale it on Z and now I have a simple basic floor by pressing W I can have access to the Move gizmo again and if ancient sigh I want to rotate my cubic and press the e key and rotate it this is like in the east max or unit by doing so now I'm going to also make this cube back to the origin and I'm going to reset the transformation the rotation so in order to do this I'm going to select my mesh instance that by the way I'm going to rename to floor and I'm going to go in the inspector there and I'm going to go in the transform of this node because I changed the transform and not the the actual mesh and I'm going to set the translation back to zero so zero tab zero tab zero and I'm going to reset the rotation so let's say that imagine that I had a rotation like this next rotation like a crazy rotation like this I can also click on this icon to reset it back to its original values it's like immunity you can reset a component and here I can also reset the scale that I want and instead of applying the scale to the transform the spatial sorry I it would have been better if I would be able to change the size of the cube so here as you can see I've still the property the resource that was open so I can click again on it and I can change the scale directly of the mesh it's like if I've imported the scaled mesh but it's going to be still normalized scale which is always good to have so now I'm going to scale the mesh to let's say five units on X 5 unit on Z and I'm going to add 0.5 or point two on the y axis okay so now I have a floor so now I'm going to select my camera I'm going to make it a bit higher I'm going to push the Z back as you can see the forward of the camera is not plus Z is not in the plus Z direction direction it's in the minus Z and I'm going to tilt my camera bits down so I'm going to press the e key and I'm going to rotate it using the x-axis and I'm going to move my camera a bit higher again so let's do this I'm going to move it higher like this if you want to move from global to local you can press the T key and as you can see now my gizmos are going to be aligned you can also click on this icon so if I now want to move the camera on its own z-axis for access I can do it like this ok so now we are going to add another cube or let's add a sphere in order to change so I'm going to first select the root node because I want to make the sphere at this level in the hierarchy I'm going to press ctrl a and I'm going to add a mesh instance that is going to be filled with a mesh resource that is going to be a sphere mesh so now that is me a sphere mesh I'm going to change its ridges to let's say 0.5 and its height 2.52 I'm going to oh that's quite weird so I'm not going to change the height sorry and that was a mistake and I'm going to put it there and I'm going to let's call it for instance player this sphere is going to be our player and I am going to also on top of this add a sub mesh so I'm going to press ctrl D in order to duplicate my mesh I'm going to reparent it as a child of player and this fear is going to be scaled so I'm going to press R and anywhere around I guess more I can scale uniformly my mesh so I'm going to scale my mesh like this again you shouldn't do that do that by default because you're going to if you are doing this you are going to change the transform of the spatial but in this scale it's ok because it's a child of the player and I'm just going to make two eyes to make it a bit funny and just to indicate the direction ok I can also change the this second eye to make it more funny ok so if I want to select go back to the default tool I can click on this mode and as you can see if I unselect I now have my scene without any gizmos so this is going to be eye and this is going to be an eye and you will see that Godot is going to complain in order to remedy this issue of having twice the same name it's going to add a number so you can see that now Godot is adding a two at the end so in go do basically you don't you cannot have two nodes with the same name okay so now that I have a player here I'm going to add some shaders in order to give it a more decent look so we are going to create temporary shaders and at the end I'm going to show you how to add interesting effects by writing your own shaders so wait till the end if you want to see that so we are going to add material to this object so I'm going to click on this icon there I'm going to go there and create a new special material for now and I'm going to click on the resource as you can see it opens another tab if you want to go back and use this icon to go in the previous edited object in a story and it says and I'm going to change the color so it's the albedo and I'm going to change it to let's liked read like this and as you can see a special material is basically basically a simple it's like the principal psdf of blender it's a simple how can I say one in all all in one I should say shader so I'm going to let's say add change the roughness so if you change the roughness it's going to be more shiny as you can see you have all you always have a preview there in the in the top of any shader any material I should say because the shader is actually the program that is embedded that is linked to the material so now we are going to do the same for the eyes so I'm going to create a new material like this new special material I'm going to click there and I'm going to change the add video to a black color and this is going to be okay I also need to change the roughness so I can have maybe specular maybe a plastic toy effect for the eye I can also change the do you know what I think it's going to be okay like this I think it's bad it's going to be okay if you want you can also go in the flags and you can also change different option by defaults but don't worry we are going to look at shaders in a few minutes or I should say in a few later I should say because I don't know how long this tutorial is going to be my goal again is to make a broad overview of what you can do with this engine so we are going to see a lot of things so now what I want to do is to not I don't want to create another material from scratch for the other eye so this is a good opportunity to learn about how to save resources in Godot so everything that you are doing in Godot is again based on the properties of the node so you can see that here I have a mesh instance that that the material and a material is actually receiving a resource in this case the resource is being attached to the two dimensions there but it's it's kind of local to this node if you want it's not saved for being reused later so that's what we are going to do now we want to save this material and we want to apply it to the other eyes to the other eye so what we are going to do is right-click on the resource that we want to save and we are going to click on the Save button so save and you can see that now Godot is telling me that I can save this resource as you can see it's the extension is G wears and TVs is is an extension it's a I would say a holistic extension it's like a global resource it's not very specialized when you read it you you you don't know that it's a material that's why God is giving you also the option to call it dot material but again it's the same thing so I'm going to call it I'm at dot material let's say and I'm going to click Save okay so now what I can do is I can select the other eye there and I can drag the material in the material section but before it is I need to open it you will see that this is a knowing some time but now I have the same material being applied to both eyes so if I'm selecting the material there and double-clicking on it I will it will change the inspector to the properties of this resource and as you can see now in the albedo if I change it both eyes reacts react okay so you've seen how to save a resource for a material but actually you can save a resource for a lot of things so let's say that you want to save a resource for this mesh you can right click and say ok I want to save this as a mesh and you can save the resource like this and reuse it later okay so one other thing that we're going to do is to make the scene a bit nicer so in order to do this we are going to add what we call a world environment so I'm going to select the main scene 19 and I'm going to press ctrl a and I'm going to add a world of all a world environments and I'm going to click create and as you can see Godot is telling you that there is an issue and this issue is that you need an environment property in order to make this node work in the scene so as you can see here I need to add the environment so I'm going to either load a previously saved resource environment which is not the case or I'm going to create a new environment so now I'm going to create a new environment as you can see everything is now dark because I don't have any sky I don't have any global elimination and I'm going to change this really fast now because it's not good-looking so this environment I can save it if I want to reuse it later so let's do it by this is a good practice so I'm going to call it my world and instance and the cool thing with this is that now if I want you at any point I can go there and right click to my wall on in the file system and I can change it there and I know it's linked to this node so I won't have to each time go to the wall environment go to the environment click open it in the middle of the node order properties and etc so now I can see separate things in a proper way I would say so now what I want to do is I don't want you to have the clear color of the project being the background but if you want to do this you can change the clear color which is in the project project settings you can go in the eye things I think it's in graphics or window something like this anyway you can search also and you can search for clear and you can see that you have environment there and you can change the wall you can change the color sorry there so you can see that it's changing actually the color of the scene the clear color like in OpenGL clear bit mode and it's affecting the scene but I don't want to do this because this is quite ugly so I'm going to go back with a great color for the environment not that white like this a great color and I'm going here instead of mode I'm going to clear color I'm going to add a sky by creating a sky it created another resource inside the environment resource which is the sky and it's the resource is not created yet but it's proposing me to create a new resource as you can see sky here it's empty so I'm going to create a new sky and I'm going to create a new procedural sky if you had an HDR file you could use this HDR in this place so I'm going to click on new procedural sky as you can see it's a resource I can right click on it and now I have my sky properties so I'm going to save this resource right click I'm going to say Sky Tiras and if I'm double clicking this resource here I can have the properties of the sky that again is indeed my world and resource X it's linked there ok but if you want to quickly edit it you can so just click on it and it's going to expand the resource so in the sky I want like let's say that I want a more colorful colorful sky like this I am going to change yours or reason for a more oranjee color I'm going to disable efflux and I'm going to also change the ground the ground is a bit it's a bit grace I'm going to change it for a more blue color let's do something quick and dirty the role is just to show you the options let's do something like this and as you can see now I can have the global elimination back and I'm also going to add other things so that's this place is where you have all the all the default post process effects so you have ambient light here so you can change the ambience ambient light but as you see it's not affecting my skin because it's currently using the sky so as soon as I'm reducing the sky contribution it's going to use this color okay but let's make it close to one and the energy is how much the ambient light is being is affecting the scene so I'm going to put a more vibrant violet color like this and I can also add for if I want with a lot of tons of properties and now the the rest of this list is basic cross process that you can enable so we can enable SS a Oh which is screen space ambient occlusion we can enable change the quality for - stance we are going to change the color of the ssao - purple color we can also enable screen space reflections like this which is going to reflect the scene inside the shaders that are using reflection we can add glow select the bloom of unity we are going to add a bit of bloom and we have also add just meant adjustments at the end in the end that is going to give you the brightness contrast saturation of your scene so this is the final color tweaks and you can also have a color correction tab that is as you can see giving you access to an image and I think this needs a gradient texture like this if I'm not wrong and I can create a new gradient texture and as you can see now inside I can change the colors in order to be map the the color of the whole thing so this is pretty powerful for artists as you can see you can tweak the different colors the different tones of the of your game really quickly and this is what I like a lot in god of its graphics is really intuitive for designers and even programmers Wow so you can see that I've changed the gradient and what I really like computer unity is the fact that by default you have all this resource predefined resources that gives you access to simple things such as gradients gradients curves etc I know in unit you have curves to but here you have a ton of resources that we are with tools in fact and school in order to prototype in to see quickly changes in your scene okay so now that we have adjusted very quickly and roughly the environment we can also go in the project settings there and we are going to search for quality quality there as you can see by default we are using GL es 3 which is the modern version of OpenGL 3.3 basically you have you have not unfortunately you don't have all the graphics possibility of the later the last version of OpenGL which is the including the geometry shader computers things like this are not included in godo right now but it's going to come in the next version of the code 4.0 so maybe if you are looking this video in the future you will already have all those features and the cool thing with this however is that if you are doing a game that is really tied to performances because you are launching on a mobile for instance you can go even go back to the old version of OpenGL GL ES 2 and in fact the GL es es stands for embedded system and it's not the the I will say the the PC the sorry the computer version the high-end version of OpenGL it's even es is a lightweight version of OpenGL ok but anyway here you can still have access to all things you can change for instance the anisotropic filtering for your textures the SAA option is as you can see disabled so we are going to add anti-aliasing here 16 is the best one so we are going to do this we are going to push all the quality very high here you can even have subsurface scattering but we're not going to use it yes for now we are going just to change this option and we are going to click on close and now you have nto yelling it's not temporal anti-aliasing like in unreal for instance but it's doing the job for now one other thing that we are going to add in our scene is a light so we are going to press ctrl a and we are going to add a directional light and now we have a light that is making the scene a bit brighter so I'm going to orient this light which is a direction light and as you can see directional lights and our pre intense because of the settings that we have in the world environment so we are going to go back in the world environment and we are going to turn down the energy of the ambient lights a bit like this and the color so this is just the color of the ambient light in case it's not using the sky contribution so I'm going to lower down both options and this directional light has some options so I'm going to click on it and I'm going to change the color of the light usually a light has never white so I'm going to tint it a bit and I'm going to enable shadows too so here in shadows you can see that I can enabled shadows the shadows are hard shadows in this case and I'm going to change the color of the shadows to a lighter color but a bit violet this is really cool because in Godot you can change the color of the shadows and the SS AO and if you want you can also enable contact shadows which is not very very very very well implemented I will say because it gives more artifacts than than good things that that nice done nice tweaks a good saying so I rally using this but it's there in case you need it so now that we have created the scene one thing that we are going to do is to script for the first time using c-sharp in this engine so but one thing that I want to do before that I want to show you how to organize yourself in Godot so one thing that you can do is in the file system you can click right click and add a new folder I'm going to call it arts and I'm going to select everything because now until now everything was art related I'm going to drag this in arts and I'm going to add a new folder and this photo is going to be called sources for the c-sharp scripts that we are going to add one last thing to note is that you can also save nodes in order to make it sub scenes so for instance here the player let's say that I want to make it as a prefab like immunity or like a blueprint in unreal and one thing that I can do is I can say to go to this part of this tree here is going to be on its own so I'm going to right click and I'm going to click on save branch as scene and now Godot is asking me where I want to save this sub scene and I can create a new folder and I'm going to call it prefabs and I'm going to say this as clearly t sen and the really cool thing is that now as you can see here i have a new button open in editor that is going to send me to this scene and as you can see in the top here you have different tabs that corresponds to the see the seams that are open right now in the prefabs folder here I have my player and in the scene I have a player instant I have an instance of a player and if I want to I can drag a new player in the scene not as a child here so let's add it so let's select first the scene and dragging and and drag a player you can see now it's a child of the scene and the cool thing is that now because this is saved as a sub scene I can open it in editor and if I'm going to change something let's say that this is going to be bigger if I'm saving the scene here I'm going back to the main scene you can see that the change the change propagates to every instance of the scene one thing to note is that you can also override in the top the different properties of the objects so let's say that I'm duplicating this player to prefab by pressing ctrl D I'm going to move it there and let's say that I'm going to in the player here console what I've done so I'm going to scale my eye a bit lower I'm going to save I'm going to go back in the scene so everything went back the way it was before and I'm going to select only this player so I'm going to select it but as you can see the only thing that I have access to is the parent node of the scene so I can scale it there this is going to be affected this is going to affect original scale but I don't have access to the sub nodes if I want to I can still override some properties of the sub nodes by pressing the right click button on top of this nut and by clicking on editable children's now I have access to the sub nodes so which means that I can override properties so I can for instance scale this I and this will be only overwritten for this I okay and you can see that here it's in red meaning that this is part of a substance so if I'm saving my main scene going back the player and changing the scale of let's say of this I if I'm going back only the two other scenes has the the the the Nuge property being changed because this one was changed manual okay so we are finally ready to start creating our first script in c-sharp so as you can see offline I've destroyed the two other instances and we are ready to add some behavior to this character so there is actually three ways to create a script in Godot you can either select the object that you want to apply the script on so here in the script section you can put the script that you want to do to this node you can click on the drop down button and select the new script option you can also click on the plus button there in order to attach the new script or you can directly go in the folder where you want to save your script and click write script a right click sorry and you can select the new script option if you if you have installed the C short version of Kudo you should be able to see C sharp here otherwise you will only have GD script visual script and native script so we are going to use the C sharp version and we are going to call the script player dot cs4 C sharp we are creating the C sharp version the C sharp script and as you can see it's there but it's not attached to the player because I've read a click I've right clicked here in order to create my script now I'm going to drag and drop it on top of my player and you will see a small icon here telling me that I have a script attached on this node and you can see here in the bottom left that the script is attached but I've made a mistake why because player is a sub scene and here in this case the script is only being attached to this instant instance sorry on the main scene so what I want to do instead which is more for clean is I want to go in the player scene and I want to attach the script to the root node of this player so now each time I'm going to apply to add a new node of type player in the scene it's going to have the script as you can see I've saved the scene and in the main scene now I have the icon so if I'm dragging a new player here you can see it also add has the script ok so now we are going to open visual studio 2019 this is the editorial that I'm going to use if you want to use Visual Studio code you're welcome to do so but I'm very familiar with Visual Studio 2019 usually in order to start the solution that was created behind the scene by Godot what I'm doing is I'm selecting the c-sharp script right one of the c-sharp script and I'm right-clicking in order to show in the file manager here you will see your script you can go back in the indie hierarchy of folders and you will be able to see here the solution that was created for your project so I'm going to double click on it it's going to start Visual Studio so in this case on my second monitor I'm going to put it back once it finishes load loading and here I have the solution that is ready to be used inside the source folder I have the player that CS script and if I'm double clicking on it it opens in as a new tab as you can see so by default you have a bit of code below boilerplate code and we are going to delete everything inside the class and we are going to start back from scratch okay so like in unity you have methods that are being called by the engine so in unity you have a wake you have start you have update fixed update and in Gulu you have very similar method methods the first one being related to start in unity or begin play in and will is the ready method so what you can do is you can override because it's a virtual method you can override the ready method like this by default you can see it's calling the base dot ready ready and if you go inside already you can see that it's not calling everything it's calling a method that is in the lower in the the low-level part of the engine which is C++ so in in this case in particular we can remove the base dot ready okay so now the first thing you want to do usually when you start learning a new engine is to log so we are going to log a message to see if when we launch the game the ready method is being called on this player so what we are going to do is we are going to call the GG dot print method so the print the print method is in the GG class as you can see and we are going to path to pass a message ok so hello from and we are going to then display the name of the the node that the script is attached to so we are going to say name name is a property of node ok and as you can see the player on which the script is attached to he know it's from node ok in this case because this is true this is valid because in the because in the hierarchy player is a spatial and a spatial is what is at the end it's a node so we can inherit from node but something that will be a lot nicer is to inherit from spatial because now I have access in this class to all the properties and methods off of spatial ok if I was inheriting from node this will have work this will have compiled but I won't have access for instance to a transform which is quite bad for making something move on the screen in 3d so this is a spatial I'm going to add this semi semi colon at the end and I'm going to save so this simple script is going should print hello from plus the name of the node the script is attached to so I'm saving my script I'm going back to good oh and I'm going to launch the project go to this building and I will be able to see in the console there hello from player ok so let's say that now I'm going to duplicate duplicate my character I'm going to put a second instance there and I'm going to launch my project again and you will be able to see two logs hello front layer and hello from player two so congratulations on creating your first hello world in god oh okay so now we are going to do to do something more spicy so we are going to delete the seven player and we are going to go back in the visual studio editor and we are going to move this character so this is the ready function it's been called once when the node is ready basically it's equivalent to the start of unity and we are now going to override the equivalent of the update method or the tick in unreal method which is called in Godot the process underscore process function as you can see the process function is always going to send the delta time this is different from unity because in unity you can press time dot delta time and in Godot it's sending you in process directly the delta time which is the time the the delta of the delta time with the previous frame okay so this is something pretty usual for any engine so what we are going to do is let's say add an order print statement here and we are going to add a low delta 4 delta time yes we are going to save launch the scene and you will see that it's going to be called every frames at approximately 16 frames per seconds because it's 0.0 16 the delta time is s 0.0 16 okay so now that you know that the process function is being called every frame what we can do is now start to move for instance our our character or player so what we need to do in order to manipulate transforms in in Godot is to first take grab a reference of the stripped that represents the current transform so in order to do this we are going to create a new variable that is going to be off type transform usually I'm calling it T and we are going to say that it's going to be the global transform okay so the global transform is the transform in world space okay you also have the local transform which is simply transform and this is in relation to its parent transform okay so it's the local transform so in this case we're going to use the global transform and now we know that T represents the global transform of the node if you go in the node here because it's where the script is attached the global transform is similar it has something like this okay I won't say it's exactly this because this is the local transform actually but in this case because player is a child of a node that is in the center of the world the transform here is the same okay so consider that this is the transform of the player it has a translation or tension and a scale and in the script here we have the transform that represents that okay so now that we have a copy of the transform what we are going to do is to call the origin field of the transform struct because transform is a struct and we are going to change it okay so how are we going to change it we are going to change it for instance by sine function let's say so what I'm going to do is I'm going to create a new vector a new vector3 as you can see it's very similar to how unity works in terms of math so basically origin here is the position of the transform okay TDOT origin is exactly like transform that position from any key so in this case I'm going to create a new vector 3 X Y & Z the X Y Z value and I'm going to say that the global global position of this transform that is not being applied yet that is going to be temporary transform if you want is going to change to to change by a number okay so this number let's say that by a vector3 sorry let's say that that I want to change the Y position I'm going to say math F dot sign here and I'm going to change the y axis of the position by a sine wave and I'm going to pass here a time and the time that I'm going to pass is going to be let's say a simple time over that I'm going to increment so here I can add appropriate in my class that I'm going to call time it's going to be equal zero at the beginning and for each frame I'm going to add Delta time to it and I'm going to pass the time there okay so now my character is going to oscillate between minus 1 and 1 on the y-axis so I know that here my character starts at 0.5 so what I'm going to do is I'm going to add a small offset on top of that let's say I'm going to add 2 point 0 F units and this is going to be good for it this simple demo so I'm going to start the game and you will see the character not moving and this is actually stressful for any beginner inga do you think you've made things right but actually you don't why because you've just changed a local variable that was a copy of the transform you need to apply this to the transform of the spatial so we are going to do this global transform equals the transform okay so this is the way that good works with transforms so now you say if you launch the game and everything should work as you can see you've simply applied a sine wave on top of your character okay so this is a lot of code for unity developers just to change a transfer but in fact you have short ways shortcuts so I'm going to comment everything here the shortcut is to simply say translation equals and your new position so translation is the local translation of this node you don't have this I think for global Global translation doesn't exists so that's why usually I'm transforming using this method and you will see it has a lot of advantage to manipulating actions from all that ones I'm going to show you this in a minute but as you can see you can also use the translation property and it works okay but let's go back to this I'm going to put this there just to show you one thing that you may ask is that here I've created the simple variable that increments but in unity we have time that time in Godot you also have a timer a global timer but it's not in float it's not a float it's a you int so I'm going to show you how it works it's simply instead of time here we are going to make a call to the static get teak ms function from the OS class and it's giving me as you can see a you int which is the time in milliseconds in unsigned integer so the thing that I have to do with this now is to simply multiply this by 0.001 F in order to have a flute okay so now I have the time since the beginning of the engine since when the engine started sorry and this is working like time the time if you want to so you can see that now my character is using the global time of the engine okay so I'm going to put back time because I know that time starts at zero and maybe the global time is not starting at zero okay because you have the loading of the splash screen etc etc okay so now one thing that you may want to do is to for instance change the rotation of the character so let's make our character rotate around so in order to do this what we are going to do is change again this local transform when I say local is the local variable T in this case in this context it's not the local act the actual local transform of the in the scene again we are affecting the global transform in this piece so I'm going to change the rotation so you have rotation a rotated sorry it exists which simply rotates around an axis so you can do this if you want to so you can say for instance that you want to rotate your transform around the tip got pieces that Y by a certain angle so you can say that for instance you want you rotate by time which is a radiant so if I'm doing this T that basis is simply representing the basis of this character meaning the three axis here so Z is the fourth X is the right and Y is the Z so T that basis represents this pages basically we call pizza basis and why represents the Y rotation okay so my characters will turn around like this and because I've rotated the the transform and I've applied it to the global transform it should work as a as a civic rotation and it's not working and again this is very different from unity if you want to make this working but what do you have to do is to just see what the method returns and as you can see the method returns a transform so I'm going to say T equals the rotation the rotated version of this transform and I'm going to put it back there okay and maybe the time because it's in radiant is very very fast so I'm going to add to damp down the value there so if I'm running this you can see you will see hopefully that your character is being rotated and as you can see it increases it increases a lot a lot a lot because time simply our value time is being incremented fast so each time I'm going to add a higher angle so this is obviously probably not what you wanted but it's just it was just a way for me to show you that you have method like this but usually what I'm doing if I want to make a simple rotation like this is on the transform you have you should have so sorry it's not it's not on the on the transform that that that's the that's the trap it's just after changing this transform for the position I can do rotate X rotate Y about it so here in this case I can do a rotted route it why for instance let's say rotate the local transform around the y axis I'm going to rotate it by 0.5 or let's say and by Delta time so on y-axis I'm going to rotate it by 10 radians per time per unit of time of time and you will see that it works ok and as you can see the angle is in radiant here the method always like visual studio is always saying you the showing you the the comments of the method which is pretty cool ok so first thing I'm changing the position and then right after the transform the global transform has changed I'm changing the rotation but what if I wanted to still use this transform in order to rotate my character so we've seen the rotated function but one other thing that we can do is to use quadrillions and quadrillions are in any engines and 3d engine and you can still have access to them so one thing that we can do is we can from the basis we can create a new basis so we can say bases at e dot basical equals sorry a new basis and the spaces accepts a quadrennium like you can see here ok so in this case I can create a new quaternion so I'm going to save quads new rot and it's going to be a new criterion and in this case I can from a quaternion as you can see by default create a new Euler angle so here I can pass a vector 3 with XY & z and I'm going to for instance here do the same thing that I've done before we are going to increase the time here put the time here and I'm going to put this rotation in the new basis okay so quadrillions for beginners are pretty strange I'm not going to explain in details what quadrillions are because it's not the case it's not the purpose of this video but basically quaternions are another way to represent with rotations without having a gimbal lock issue a gimbal lock issue is that if you separate three axes you can get the order of rotation like it's in the case of its it's the case in the Euler representations XY and Z and you can have depending on of the order of the rotation you can have you can miss an angle you can it's hard to explain in in the short way but basically the order of rotation matters in Euler angles representations so using the rotate x y&z functions but using quadrillions you have a way to represent the quite the the rotation directly basically if you create a rotation that like this the rotation is always going to be represented like this okay it's based on complex numbers and if you want to dive into quadrants I will put reference links in the descriptions it's pretty hard to understand from the math point of view but it's pretty easy to use from the chem developer point of view okay so if you are coming from unity or unreal obviously you should know this so we've created the new rotation which is the new quaternion from a Euler angle so it's going to take our Euler angle and convert it to a quaternion and now we have a new rotation that we can put in the basis again the basis is what is the tripod of axis so XY and Z and the rotation here that we are passing to the basis we are creating a new basis is going to affect the orientation of our tripod and we are going to say that our transform that we are going to modify receives this new basis ok we are going to save and we are going to see a similar rotation on the y-axis and you can see that it works we have a quaternion making a rotation on the y-axis okay so the cool thing that we can do now isn't now that you know this we can create let's say a slope okay so what we are going to do for demonstrating a slope which is a smooth way to look at something look at a rotation look at at a point source or a target what we are going to do is we are going to create a new script and this script is going to create a simple behavior for making an object move in the scene okay so what I want to do is I want to create in the scene a new special so I'm going to press ctrl a I'm going to call it I called the spatial node here I'm going to call this target and the target I'm going to add a new mesh instance some mesh instance like this and I'm going to in the mesh option here I'm going to let's say add a prison prison no this is not that that pretty so I'm going to add let's say that I'm going to I don't have any good shape in mind so I'm going to add a sphere okay let's go back for another sphere and I'm going to select my target and I'm going to move it in front why I'm moving the target instead of the mesh instance because I don't want you offset the mesh from its origin so if you look at the target now the origin is there and the target is inside being upset that on the x-axis I want the parent just to be a container if you want okay so I'm going to put the target there and I'm going to create a new script in this first folder right click new script and I'm going to call this target dot C sharp I'm going to press ENTER and I'm going to add the target script on the spatial okay so now I'm going to go back in Visual Studio and you will see that Visual Studio is asking me to reload the solution so I'm going to reload and now I have access to the target dot CS script so now why we want to do is we want to create a simple script that moves the target and after that we are going to go back in the player script and we are going to make this character look at in a smooth way the target okay so I'm going back to the target class and I'm going to delete this function the the the bollard plate code in the function and I'm going to override a new function and this new function is called the input function okay so I'm going to override the input function okay the input function has a parameter that is called at events and because event is a property even story is how can I say that is a reserved keyword in c-sharp automatically via Co is adding an ad in front which is not that great so I'm going to say e so e is representing any event any event sorry I'm going to say right or at least try it's going to represent any event from godo so as you can see here if I'm training the key events by pressing ctrl s I'm going to save the script if I'm running the script like this you will see that when I'm moving the mouse I have a input even Mouse motion if I'm pressing the key I have the event key option I have the resize event probably or no not in this case so it's not it's not being filtered there but this is cool to know here I can filter Evan's Evan's Evan's units excuse me French accent and grammatical errors so in this case I'm going to filter the e variable I'm going to say if e is a key key board oh sorry input key kill them you put events like this and I'm going to say that events like this the cool thing in c-sharp is that you can check for the type like this it's not that performance oh don't worry I'm going to show you a better way to do what exactly I'm doing there but it's just for learnings sake for the learning sake I'm going to show you this method and after I'm going to show another more proper way to do this but here the thing that I'm doing is that I'm checking that the type of the events the events that receiving is input even key so it's a key okay I'm going to use to rename this variable to another to two key events meaning that key event is represented a real event key and here I'm pretty sure that when printing the key event it's not I'm pretty sure it's for sure when I'm going to print the key even variable I'm only going to receive even key event so you can see I'm moving the mouse it's not working but as soon as I'm pressing Keys I have the event being locked there okay and it's not detecting at the press and release so as you can see if I'm pressing spacebar without producing whatever good-o is still filtering this as a key event so here now that I have this event even what I can do is if key event one that is pressed now here I will be able to filter the fact that the event the event is pressed this is a really difficult section for French guy and here is the list is not it's not there because you can do simply this press or else he has been released okay so here I can say press I can duplicate my key my my lab by pressing ctrl D and pulled up and down in visual Co gives you the this nice feature of moving the line that is currently under the cursor and now I'm going to set key released I'm going to save launch my game and you will be able to see dance I'm pressing key pressed so the key is pressed I'm releasing key with East so I have a way to filter the the fact that the key has been pressed or key has been released here what I can do is in my case I just want to move when the key is pressed and what I want to do is now I want to filter the the type of key so I'm going to say if the key events as has a scan code of key list that let's say up now I know that this is the up key but you can see that the key list is giving me a you int and a scan code here once a UN sorry and the key list here is an is a minim so I'm going to cast it to you int and now here I'm going to say print up a rope arrow and I'm going to save I'm going to play if I'm typing any order key I don't know and if I'm pressing up I have a row being filtered okay so that's pretty cool now I know how to do the other keys I'm simply going to make an else--if else--if and else f like this you know what I'm going to make an if else if here because here it's going to be either and pressing up either and pressing down and here it's either and pressing the left or I'm pressing right and you know what it's just going to be ifs because it's going to cancel the motion so we are going to do this in a nicer way okay so what I'm going to do in this class as I'm going to add a vector3 hold motion and by default it's going to be equal to vector 3.0 which is a constant okay if you go into vector 3 class you will see it you can press ctrl + click on it and you can see that you have vector of three dots right except there are zero it's a static variable and what I'm going to do is I'm going to change this motion variable depending on which key I'm pressing so if I'm pressing up I'm going to say motion that Z in this case because Z is this okay and in this case I'm going to say minus equal a speed and the speed I'm going to declare it here five for instance and I'm going to do the same for down but now it's going to be plus left it's not going to be Z it's going to be X so if I'm pressing the left key you can see the x axis is pointing in this direction I want to go in the other way so it's going to be minus speed and if I'm going to press the right key I'm going to go in the other direction I'm going to play and it's working actually I'm changing the motion variable but I'm not applying this to my transform so I'm going to go in the process function override process function and every frame I'm going to change the transform of the subject so I'm going to store the transform the global transform of the subject in the transform variable and what's the problem here I'm inheriting from node and not spatial so now this is a special global transform I can cache it there and I'm going to do see got origin and I'm going to say plus people motion time Delta Y time Delta because I want the motion to be related to time to be time dependent and not CPU dependent okay so now it should be not fine because I didn't applied my transform this is again a quite redundant error so I'm going to say the global transform of the spatial node is going to be equal to the transform that I just changed before so I'm going to press play and I should be able to move as you can see my ball but it's not that great because I've just changed the motion and when I'm releasing any key the the ball is still continuing and I need to console the motion in order to make it work and each time I'm pressing the key I'm adding to the motion so as you can see this is not the ideal way of doing this okay actually what I want to do instead of putting the speed there is also just saying minus one and plus one plus one plus one and this is going to change the motion the the actual motion which is going to be more a direction so I'm going to pull the direction control or R is ctrl R twice is going to rename the variable everywhere and what I'm going to do is right after removing my object I'm going to say the direction equals a factor of 3.0 so I'm going to reset the direction and here I'm going to time the screen this is I would say more a nicer way to implement this if you want but it's still a bit clunky as you can see when you're changing the keys so I don't want to go with this approach I'm rather going to do it the proper way and for me the proper way in guro is not using in this case the input function okay we are going to use what is called actions so I'm going to remove the input function but for now at least now you know that the input function exists we are going to remove remove sorry the key input function and we are going in the process to call to create our own input detection okay so before doing this we are going to add what we call input settings in God so in bodø here in the project settings we are going to say project settings and we are going to go in the input map and as you can see you have different even events input story exactly like in unreal you can bind an action an axis sorry and in unity you have the input manager where you can at Evans if you can add inputs sorry so now what we are going to do is we are going to add a new action that is called let's say move up we are going to move down I'm just pressing enter move left enter move right enter and now inside those new for action we are going to set up different keys so here I'm going to click on the plus button and I'm going to put up key and move down I'm going to put a new key which is the down key you need to press the button ok this is the left and finally this is the right okay so I'm going to close that I'm going to go back in the source code and now I have the ability to get the value of those inputs so if I'm printing the inputs that get action strength so the strength of the action corresponds to how pressed is the key if you want it's going to be 0 if it's not pressed and it's going to be one if it's pressed and I'm going to type the name of the input so move up constant so now if I'm running this and I'm pressing the up key you can see it's 0 by default and I'm pressing the up key and it's 1 releasing it at 0 okay so the cool thing is that now in this float I can in this in this line I can print the the strength of the action and now in a float that I'm going to pull or isn't all of vertical for instance I can get the move up function and I can subtract the move down action like this so I'm going to get the value of move up if move up is going to be pressed it's going to be it's going to be one if the down key is not being pressed at the same time it's going to be 0 so 1 minus 0 it's going to be 1 so vertical is going to be 1 meaning that vertical represents the information that we are going up so it's 1 if we are pressing down and the up key is not pressed this is going to be 1 if I'm putting a minus here it's going to be minus 1 and move up is going to be 0 hence the fact that vertical is going to be minus 1 so we have a way to represent the vertical motion of our character our spatial I'm going to duplicate this line pressing ctrl D or isn't all and you get me we are going to move right move left so now vertical and horizontal represents the horizontal and vertical motion of our character and what we are going to do is we are going to say motion equals a directions I equals a new vector3 vertical on the horizontal on the x-axis 0 on the y and vertical on the z axis we can be moved to that line which is not needed anymore because we are changing this every frame now we can save this we can launch and you can see that it's working out just like inverted the Z the vertical axis so I'm going to just swap this so this is down and this is up because the z axis as you can see is inverted compared to what I've stayed in the in my scene so I want the down key to be positive I want and I want the up arrow to express as a negative negative value so now it's each one and now I have a simple target that I can move around using the keys and you can see that I've also added it adds also the the directionals but in this case the issue I have with this is that if I'm pressing down and right at the same time it's going faster because it adds to the motion the motion the directions are is not normalized so what I need to do is to normalize the direction if I'm pressing for instance if here it's 1 and here it's 1 you can clearly see that the vector is not normalized so what you need to do is normalize the vector so it has a 1 unit length so now it's going to be at the same speed okay so now we have a way to control the target and what we want to do is to make our simple character look at the target but before doing this I'm going to show you a nice way to serially serialized parameters in godo so here the speed is changed is not visible in the in the editor in order to make this visible in the editor you can add the attribute called export and as you will see by pressing control s now in the editor it's now not visible now because I didn't build but I can click on the build solution here button and you will see that now I have access to the speed and if I change it to 10 for instance it's going to be twice as fast it's exactly the same thing as putting the serialized field in unity or blueprint editable anywhere in okay so I'm going to put the speed down to five and I'm going to save everything and now I'm going to go in the player and I'm going to with a reference the target to the player okay to do this we are going to use again export but we are going to to do the the issue right now with Godot is that you cannot export any type that you want so many so it means that I cannot export a spatial for instance what I have to do is to export a path a node path and the node path correspond to the path of the node in the scenery and then I can get the node using the get node function and Godot is going to have the reference final the final reference for the node so this is quite cumbersome but you will see that at the end it's not that much so you just have to say I want to export the node path I'm going to call that target path usually I'm adding path at the end of my variable name this is going to be exported so what this gives me is that when I'm building you're going to see in the player script that now I have a target path and I can assign when clicking the assign button I can assign any node here and I'm going to assign the target spatial so you can see that this player script here is referencing the target okay I'm going to save my scene and I cannot do this in the player scene here because I don't have access to the node so if I would want to make something more generic I will have to for instance maybe spawn a target for from the player script or maybe find a node using a name or maybe find a better design pattern for doing this for me but in this in the context of this tutorial it's going to be okay okay so we have the target in the clear script so now what I can do is we have two paths of the target in the bearish clip not the not the target itself so what I want to do now is I know that target is going to be a special or even more I know that the target is going to be a target okay so because target is a special I can cast it so that's what we are going to do and I'm going to call it target like this and in the ready function they're just after printing my name what I'm going to do is I'm going to say that target is equal to get node and we're going to get a target okay because the script is attached to the spatial know this spatial node is a target okay because target the target scripts inherits from spatial so I can do this and as you can see the get node function is asking me for path I'm going to say target path in this case so it's going to grab the spatial and cast it to a target and now here I know that target is a target okay and what I can do here is let's say just to show you that it it's working and let's say print the target global transform the origin so we're going to print the position of the target like this I'm going to save I'm going to play and you will see dance we have no errors and it's time I'm moving the targets you can see that the player is aware of its position okay so now we can make the look at that we wanted to do so in order to make a look at you have different ways of doing this so what we are going to do is here before modifying the transfer applying the transform to the global transform of the player we are going to find a way to create our our look at so you can do a look at function you can say key dots looking at which is giving you back a transform so if after setting the transform you do something like T dot look at you pass the target that you want to look at to so in this case it's going to be the target that origin that global transform that origin you need to pass the up vector that you want to make your the up vector basically that will help go to create the new basis because it involves cross products in the under the hood so in this case because it's going to be okay in the most case because we are on the plane I'm going to pass the vector 3 that up with application upper case you and again this transform this looking at option function is returning a transform so I'm going to say at the end the global transform is going to be equal to the this new transform that has been constructed by the looking at function okay so it's a bit complicated in this case complex in this case but trust me so as you can see it's trying to look at but the character is probably reversed so yes I think it's - see and this is due to the fact that it uses the opengl convention where Z is negative so what we are going to do is in this case we are going to find a better way than using the look at all wise you would have to flip the z axis of your character meaning that inside player will have to rotate the original direction of my character so if I'm doing this in the proper just to show you here meaning that I'm going to put the eyes in the other direction which is not what I wanted to do but just to show you I've I've saved up the player it's going to look at in the proper direction just because it's like yes it's the opposite OpenGL way of doing of flipping the Z so I'm going to put the direction back to the front just so it's not that annoying I'm going to cancel to comment the the sinus the sine wave that I've added before and we're going to find a better way to do that so you have another thing that is the spatial look at function so you can see that it's its global it's the same it's rotates itself so the local - z axis points toward target position so I could have also instead of reassigning the transform I could also have done this look at would have will have worked will that apply directly the transform thank you can see it's working in the opposite direction because just of what I've been telling you before but the cool thing is that again by having a transform there what I could have done is like something like this like look at transform people's this and in this case I could have switched the basis to Z access meaning flipping the z-axis of the basis by doing a new basis passing the pages so I have to create a new basis new basis again a basis is just a combination of three axes it's nothing to be worried about its X Y & Z it's exactly the tripod that you have there okay so the new basis is going to be equal to the look at transform bayless okay so the look at transform that I've created before basis I'm taking the basis then the z-axis and flipping it x equal minus 1 so now the z-axis is flipped the other way around and I'm putting the new basis in the neutral in the look at transform reflections from that basis equals this new basis and now I'm putting directly the look at transform so I'm going to show you that it works and then I'm going to show it I show the code and explain it once again just so you you are comfortable without what I'm doing so again I'm creating a transform that is going to represent the look at transform so imagine that from out of the blue we are just creating a new transform that is representing a transform that is looking at the target so this is the part okay the objector is just so guru can do its magic and we are just passing a vector that is not aligned with the looking transform so make sure that this vector is always not in the how can I say it's always different from the final transformation that you are going to do if you want to because under the hood as I said it's going to use cross products but basically you have to put a vector that is out of the out of the way of the looking at transformation so now this is representing this look at transformation but with the Z flipped again it's putting the minus Z of the spatial looking at the target and we want the Z looking forward so what we are going to do is we are going to create a new basis for this new transform we are first grabbing the bases the original basis of this transformation and we just want to flip the Z so we'll flip to Z and we are putting it back to the same transform okay and then we are applying the distinct transform to to the to the global transform and looking at transform just remember that it comes from the T transform that was created before here MT was the the transform that we've applied previously I can even comment this too and I'm going to prevent this with the offender I can even comment this and I'm going to be fine okay so if I'm running this I should have the same code same working code okay and I can even add back the motion of the sine wave and it's still going to work which is logic logical we are using only one transform and from this transform we are constructing a look at transfer and and we are applying this final transform okay so cool we've seen how to do to do this but before I said I wanted to create a smooth look at here it's one to one it's like directly looking at the the target I want to make it smooth sir so how to make it smooth you just have to create quadrillion magics and I'm going to show you this cotton magic and if your community you are going to be at home don't worry it's going to be super easy and something that you've probably seen before so I have this new basis the and this basis corresponds to the look at basis meaning that imagine that if my sphere target was there I have three axis with the Z pointing toward this direction and the X being there and why being properly calculated okay so I have a basis looking at my my sphere so what I want to do now is create a quaternion that slurps that interpolates between one original rotation and the new basis that is going to be the the parameter that we are going to pass you a quaternion okay so be with me I'm going to type the code and explain it as we go so we have the new basis I'm going to just console this or command s sorry and what we are going to do is first we are going to before affecting the transform here we are going to store the basis the original basis or with G no basis and this is going to be T dot basis okay so basically it's the basis of my character there okay so what I'm going to do is I'm going to create a quaternion out of the spaces after the end and I'm going to call this form what and this is going to be a new quarter onion from the original basis okay and now I'm going to duplicate this line and this is going to do two quad and this is going to be the quaternion were going to interpolate to and this is going to take in two parameters the new basis again the basis that looks at the target so we have two bases floating in the space imagine this in your head we have two bases floating in the space and we want to smoothly interpolate between the two of them and to smoothly interpolate between the two bases what we are doing is first converting those bases to quadrillions and then using a cool method from the quadrillion class we are going to interpolate so we are going to say from the quaternion from quad we are going to say dots and slurp we're going to smoothly interpolate using this slope function we want to interpolate to the to plan which is the second rotation made from the look at bases and we want to put a timing value so a percent value of the interpolation so in this case we are going to do Delta time times a speed that we're going to store slurp sloppy that we are going to store it and this is going to be ten by default let's say or let's say five okay so again here we are not dealing with with a real speed in fact we are dealing with a percent of the interpolation okay so imagine that this is rotation a we are going to partition B and this is the percentage from A to B so where we are from A to B let's say that we want to move fifty percent from A to B so now a is there okay and the frame the frame after we are we want to go 50 percent from rotation a to B so now we are there so frame after we want to go 50 percent from firm A to B now we are here 50 percent from A to B we're here and you can see that a is getting closer and closer to be so it's a percentage it's like a normal interpolation but using quadrants okay easy stuff so now that we have this again the slope is returning a quadrennial so final rotation what what we want to do is to put the final quaternion as the basis of the final transform okay so look at transform is at the end the transform that we're modifying so maybe with what we can do is call it the new transform this is more clear ok so we start the new transform is going to be the look at we do our stuff with the rotation and then the new transform is going to receive a new basis and the ski base is going to be a new basis based on and you can see that you can pass a quaternion there so based on the final putt and then we are plying we are applying the neutrons from there okay so I'm going to test this and if it works I'm going to explain everything back then I have a common error and I'm pretty sure it's going to be about normalizing the quaternion quaternion that slurp parameter in P and you can see in the I have an issue eater and usually the issue is that I forgot to normalize the prytaneum so I'm going to normalize the quaternion this is internal math precision I think in this context I'm going to play again I still have an issue it is not normalized form entropy and Part B is the two quaternion and to normalize this forum and you know ffs I'm going to normalize this one to normalizing a quaternion means that you take all the [Music] you take all the you take all the parameters and you make sure that the length of the quaternion is 1 but anyway it's not working so let's debug that and let's see why it's not working ok so we're coming back to our code and we are going to read that again I'm pretty sure you've seen that mistake from the beginning and mistake has pretty obvious is I am flipping one basis in the other direction but the other one is not flipped meaning that when I'm launching in the game I'm trying to rotate from like something that is inverted we have something that is not so what I'm going to do is first I'm going to comment the daisies there I'm going to relaunch my project you can see that it's going to work but we first of course but now at least I have the smoothly interpolation the smooth rotation and that is working and at the end the new basis here I'm going to flip it I'm going to say the new basis that Z as ago is equal to the flipped axis and I'm going to say the new basis I think it's okay like this I think I can do it like this correctly that's better looking so I'm not flipping one of the bases and flipping the result basis oh it's not working that well what did I'm a was my mistake I just realized this is not going to work because and so I removed what I was writing because on the next frame the basis is going to be transformed and hence the weird behavior so I will have still to were to invert my bases here and I'm going to invert my new bases here my original basis here I think this is going to board or joining bases cut Z times minus one I think this is probably going to work no it's not working so let's investigate why so I've post the video I've just removed this and I'm just going to show you an approach that that I think is better in order to understand at least the math and I'm going to to show you how I will deal with this in fact they're looking at function is a nice way to do it quickly I would say originally if you are in a prototype in prototyping session you will go in the player you rotate your player and boom that's done but in this case if if imagine that I would really want to have the bases inverted I can I could not do it with looking at because it's going to the opposite direction the OpenGL way is minus Z so one thing to do in this case is like not bothering about this so you remove your transform function so everything is going to break of course and IDN you are going to use the teeth so I'm going to use the T I'm going to apply everything from the key but the original basis is still the original basis here but the new basis is going to be completely new newly created basis okay so I'm going to create a new basis and this so a new tripod imagine it's just a tripod imagine a new tripod okay and I'm going to construct this tripod from scratch and it's exactly what the looking at metrics is doing under the hood but now we're doing it by hand by flipping the right Z and you know what in order to be very thorough in my explanation I'm going to open drawing board and I'm going to show you exactly what what we are going to do so let's say that I have a tripod like this pardon me I'm using the mouse the mouse so it's not it's not good so I want to go from a tripod like this where this is the forward to let's say a rotation that is crazy looking in this direction this is representing the arrow like this so this one is this one so let's say that I want to go from this space to this spaces okay so one thing that I have for sure is to basis okay so one thing that I want to do is to first consider the vector that is going to look at my target so imagine that I have a target there you can see that this one is aligned to the target and this is the origin on one and it's not aligned so of course you should imagine that this those are on the same on the same level okay so I want to first define my new basis with this vector so the first thing I want to do is to say that yes it is to say that the new base is let's call it look at faces it's going to be more more explanatory I want to say that the look at bases is pointing there is the Z component sorry it's pointing directly at the target and in order to do this it's simple vector math so toreador again the global transform origin - my position toppled transform so it's T dot origin because remember that T is the global transform there okay this is simple math I have let's take the pen I have the position of the target - my position this is going to give me this vector okay again it's not normalized here we don't care for now it's not normalized so I have this vector I get this giant vector okay so the Z Direction is good now I need to reconstruct this vector and this vector and in order to reconstruct the vector you probably know about this at school I think it's called grant Schmidt in math but anyway we are going to reconstruct this so I need a vector that is not aligned with this one the perfect candidate is the up so I'm creating a up but you can see that those two vectors here are not orthogonal or two orthonormal are orthogonal in fact meaning that they are not 90-degree and every basis is 90 degree here in nineteen ninety and nineteen this is what represents a basis okay so what we are doing here is we're taking the up vector which is not aligned with this vector but it's not 90 degree here it's maybe I don't know it's maybe 63 degree and I'm going to use a cross product that is going to give me a vector like this that is fully 90 degree with the fourth vector that is pointing toward the target okay so now those two vector they are not normalized but they are orthogonal okay and this second vector is going to be my X Factor okay and not X Factor and the last one which is the final up that I want to create so let me undo this and consider that I have this one the final one I'm going to select again this right this fourth vector sorry and this right vector and I'm going to do a cross product again and I'm going to have another vector that is going to be 90 degree from the fourth 90 degree from the right and I have a tripod but the final thing is that this tripod is not normalized meaning that the vector is here why not of unit one so I need I will need to rescale my vectors so they are unit one okay and you have a function that is doing this automatically for you in godo which is called Auto normalize and now at the end I will have a base like this one it's not right pancham in the right direction in the diagram but I hope you understand I will have a basis that is going to point toward the target okay so the first vector which is not normalized is the big one so this one okay the second one I want to do is the X so we are going to say that the look at bases that X is equal to the vector three cut up dot cross we are going to do a cross product with the up vector of the seen when we say vector three dot up it's it's constant that is saying 0 1 0 so it's the world up okay it's not a local up it's walled up so we're going to cross the up vector with the previously calculated vector which is stored in the zip basis okay so with the previous vector here so now we should add this vector okay again not normalized for now and the final one is the up so we are going to say the wine and the y is going to be to look at basis X with the look at basis Z and it should be okay like this so now I have the look at paces okay which is this one and I'm putting it there and I'm putting it in the final basis so we should have two behavior that we want oh it's broken meaning that I've inverted some cross product so it's probably it's probably this one I'm going to test and I'm going to explain myself just after if it works and yes it's quite working okay so I'm going to explain something about the cross product so I hope you you have understand what I'm saying there meaning that if you have one vector and another vector they share a plane okay even if they are not aligned so let's say that we have this and with this you should know about that cross product if you are a developer but just in case you have two vectors if you cross them together they will go they will give you another vector a new vector that is going to be perpendicular to the plane they are forming okay and the order matters in fact if you are crossing this this one with this one depending on the way the vectors are interpreted by the engine it's going to be in this direction and if you cross this one with this one the other way around you will have the vector going in the opposite direction meaning that the basis will have one axis flipped so if you have one axis flipped it means that the the the basis is not in the good cording in the Goods coordinate system meaning that you will have an issue hence the fact that I've decided to switch this axis so I'm crossing the up with the Z basis the previously calculated bases the forward vector the actual forward vector that we want and finally I'm doing the same at but with Z and after the X meaning that I have reversed the cross-product and one thing that is not safe with with what we have done is that the basis is not normalized meaning that the one of the axis could be could have a length that is not unit based and usually we want unit basis so I'm very surprised that Google didn't throw an error right away but if we do a print basis here a basis see for instance we will clearly see that the look at basis that Z dot length so we are going to grab the length of this vector again Z is not a float is a vector so it's a bit confusing for beginners or for unity developers because unity developers usually have transformed dot forward which represents which says that it's a vector direction okay in this case Z is a vector so here I'm pretty sure the length won't be 1 and the basis will be scaled you can see it the base the the Z vector is not 1 and we want unit vectors so in this case we are it's ok it's working because right after our script what our line or basis construction what we're doing is here we are taking to look at basis as a quaternion and we are normalizing the quadrennium ok if the basis if you wanted the basis to be normalized what you had to what you have to do is to say look at Bayley's dot also normalize ok and this is going to normalize the the basis and you can reapply it like this so your normalizing your basis it's giving you back a new basis with unit length vectors directions and it's going to be ok and if I'm panting here the the Z of the basis and the length I'm going to say look at pieces that give that length you are going to see that it's going to be one due to the previous function call and I think that we can even forget to normalize here of the quadrillion and it should work because the basis is being normalized okay if you didn't normalize your basis the quaternion will would and if you didn't know alter normalize the basis meaning that the vectors are scaled differently and the question was not normalized you probably will have an error saying that the quartering and it needs to be normalized as you can see quadrillion is not normalized okay because the values of the quaternions X Y Z and W they all need to be normalized at the end so you cannot have for instance x equals to 1 and W equals to 0 point 1 because it will give a length of like not 119 so it's not it's not good okay so I think it costs less to to normalize the quaternion because you will have only to normalize this quadrant and the basis is used only there and you won't have to normalize three times because remember that Auto normalized normalizes the basis all the work all the vectors in the basis the X vector the Y vector and the Z vector and the quadrant on here normal the normalizes only X Y Z and W ok so I hope you understood what I'm saying I hope you are familiar with basic game development man again programming math and I hope you understand also the power of God Oh giving you access to all those bases way of thinking I know it's not that intuitive if you come from Unity but what I'm showing you here it's the professional way of thinking about transformation it's things that you think about when you're developing for instance an engine and guru is giving you access to this of course you have neat function like rotten eggs what at work cetera but you're not going to good very far if you don't understand this basic stuff ok so now we know how to we know how to - you have a good how can I say a good understanding we have a good understanding of transforms in in guru what I want to show you is now hopefully basically a medley of different things that are nice to know about guru so we are going to first I'm going to remove this ok maybe I can still keep the the floating sinus sine waves it's pretty pretty fun to see this character floating and looking at okay so undercook the cool thing again is that imagine that now I want to duplicate my player I can duplicate my player there and I can reassign the target by default it should be fine but by precaution by how can I say that in English I forgot my words my vocabulary by but in order to do no mistake I'm going to clear the the target and I'm going to reassign it to be sure and now I shall have two players following the target but again remember it has moved because in my script here I'm directly affecting the origin as affecting the position so what I should do is before my script goes into the process function and restore the image plus its origin so I'm going to do in its origin so the original position of my character and I'm going to sit off my spatial I'm going to save all things from that origin so now that I have the original transform before the script starts and starts calling the process function what I can do is I can say the origin is equal to D orbit the original origin plus the the sine wave okay plus the vector that is making the sine wave moves of course I can also affect only the Y position of the origin but in this case I'm just going to add the vector or like this pretty basic stuff so you can see that now I have two characters floating around doing their own stuff it's a bit weird but it's funny to see okay so one thing that I will do now is I will add I will show you how to add randomness in gudo because this is something that you need to have in order to develop games random functions so in god oh you can have access to random number Jen one them generated numbers by pulling the GED class so we are going function on the gd+ we are going to say for instance sine offsets here sine sine value to cross your and we are going to say in the ready function that the sine value is going to be equal to g d dot random and round you can see that you have different run functions you have the run f function that is giving you a number between 0 & 1 you have the Run range function that is going to give you a number between two double ok doubles not floats and this is what we are going to use in our case so we want the character to move to to also oscillate between negative number negative sign value and negative and positive sign values so what we are going to do is put two numbers we are going to say between 0.5 so it's a double so you don't have to put the F but if it was float numbers you will have to put in this case it's a double and 1.5 let's say but everything is a double so I'm going to test it back to your float so at the beginning of the call of ready function we are going to store the in the sine value a random number between 0.5 and 1 point 5 and we're going to use that here okay so both my characters won't go won't oscillate to the same height or should it's not that obvious so I'm going to lower this between zero and one point five to be sure that I didn't make didn't make any mistakes hmmm let's go back to the code the source code okay my bad I just added the value what I need to do is multiply by the value so it's going to be between minus the sine value and the value that we added here so I can put back this and I need to add the offset which is how high the character is I don't want the character to be us to be moving below the ground and because we added in origin this is going that the position of the character is going to be leave the original position it's going to be also oscillating down and up around this point okay make it makes sense I bet it makes perfect sense or so I'm going to move my characters like this so they are going to also get around this point so I'm going to save I'm going to play and you are going to see that it is working actually so both of my character are oscillating around their points and they are oscillating I'm going to put between 0 & 1 point 5 so it adds a wider range of 480 in the random it's not working it's preached quite strange so one thing to do in this case it's to print the value so I'm going to print assign the value directly to see if I have two different values at the beginning so yes I have two different values but maybe the range is not that it's not that high so maybe what I can do instead of changing the oscillation I'm still going to be between 0 & 1 I'm going to try to - to change the speed of the of the timing or if I want to create an offset type I can offset the time that I'm going to just scale the the value so one character should be if I'm doing this and let's say I'm going to do this between 0 & 5 1 like the characters 1 at the same speed but they are still going to also oscillate between zero and one and still going to be what I need to to see okay so you can see that one character is like has a speed of 3.1 and the other eight 3.78 so hence the fact that they are d synchronized okay so that was the way to show you how on the network this is going to be sine speed now I can add if you want sine offset of zero I can say that the sine upset is going to be a GG dot long F this is going to be giving me a number between zero and one so if now I'm applying a multiply by the sine offset it's going to be between zero it's going to also be a between negative sign upset and positive sign of set which is a random number between zero and one so you can you will see that one is for instance in this case oscillating a bit less so it should have like a value it's probably 0.5 and this one is probably one as you can see so this is another way to query random numbers so this is cool this is working we are good I'm going to show you another way too that is pretty cool we are going to see how UI works in a minute but but before that I want to show you how to detect collision in godo and we are going to see a bit of wreckage raycasting too because this is common vocabulary for game programmers I will say so what we are going to do is to detect collision collisions so what I want to do is to okay let's do this like this we are going to add we're going to add a note called area and area is going to be as it says an area and as you can see you have a warning saying that you have no call his own shapes so we are going to add a collision shape so the collision shape is a bit like the colliders is not a bit it's like the colliders from from unity so you can add the collision shape like this and the shape you need to add is of type shape as you can see so I'm going to add in this case a cube shape and under the area I'm also going to add a mesh instance so we can see visually we can have an idea of where the shape is so I'm going to add a cube yes and the shape the collision shape as you can see has handles on top of it that you can see there and that mimics the visual properties of our code or our cube in the bottom okay so what I'm going to do is I'm going to put this area right there and we are going to detect if the ball is entering and this volume okay so if I'm launching the game nothing changes but what I want to show you is is this simple stuff if I'm entering the cube I want the cube to become transparent for instance and I want the and when I'm going out I want the cube to go back to normal okay this is going to be a simple mechanic that it's going to show you how to deal with materials and how to deal with collision detection while at least I will say triggers collision detection is another story but we're going to do that later I'm just going to March before like this and I'm going to again show you what I just said so this area is going to be three but called trigger box we are going to add another script this script is going to be called trigger box we are going to open visual studio we load Visual Studio yes trigger box there and this is going to generate not note that area okay so we are going to override the ready function and we are going to see now something called signals in godo signals is just a way to emit event events from an object so if you are selecting a node and the node section here you can see that you have different signals so by default a node as the ready signals you have three entered meaning that the object has entered into this tree as you can see those are the basic signals that we can override using virtual functions but that we can like detect using the virtual functions but you have also like point sense because this is an area node and a collision object you also have like mouth mouse entered mouse exited you have visibility change because it's a special and you have a lot of notes a lot of signals sorry because it's an area so let's first start by the mouse entered signals okay so how to connect a signal they just called the connect function you then type the signal using this convention like the real signal name here without the brackets so mouse and third you say where you want to call the callback and the callback is going to be on this object and let's pull it up on Android on Mouse in this and then go to X accept expect that you have a function call on nose and hurt on this object and this is the function so I'm going to say the prince mouse-over okay so I'm going to save the script I'm just going to connect the mouse enter it function that event sorry on the on mouse enter it function easy enough I'm going to play and this is not working as expected so noise and threw it on this object almost almost Android should be fine one thing that you have to do is probably check on the inspector in the collision right on the collision shade maybe okay transfer matrices okay the shape is okay that's okay I'm I'm a real idiot there because I was expecting something to walk without attaching any script so I'm going to put the trigger box script on the trigger box which makes more sense and now as you can see the mouse over is being triggered when my mouse is over this object so this is not what I want what I want is to know when a another thing enters in the in the script and you can see that this this sphere has no collision shape so we will have to add a collision shape to this target so a little target here what I'm going to do is to add using control a a shape so a collision shape and in this collision shape I will have to in these inspectors set this shape as a new sphere shape the sphere shape is a bit big so I'm going to so you can see this is a big mistake I'm often doing is that I'm killing that the top the parent and you shouldn't do this you should always add a scale of 1 so in this case it's okay so the mesh instance here should have a bigger wages so that's that's weird because translate here should be ok now you can see that translate is not okay so the this the transform is like this so I'm putting it back in the center the mesh instance here shouldn't have a transformation scale we're not unified but the scale of the wages should be smaller the height should be 1 or 2 - 0 - okay so now I have the target here thank you make it higher okay so 0.2 and we open for apparently it needs to be twice as much the radius apparently and now if I'm removing the shape like this and adding it in the hierarchy under the mesh instance it should be the same size so I'm adding the cause even shape here not collision polygon so called even shape here I'm adding a sphere and I'm I can now in the shape USA 0.2 and now it's going to be the same size as my sphere okay perfect so what's the problem now is please use this child area static body rigid body etc make sense so now what I need to do is to change the type of my target to to a kinematic body actually because kinematic body is as it says as it says sorry body that is moving buddy where is the body is something that is known by the physics engine so I'm going to change this target to a type of kinematic body the kinematic body yeah and now it doesn't contain any more okay so I can have a shape I can have steel my target it will still work because kinematic body inner it's from I think kinematic body you know it's from spatial so if I'm put in here that is it that it's actually nominees in a kinematic body excuse me everything but steel board it's not working the good way because the kinematic body is a physics object so we will have to change the way the the body is moving but for now it's going to be okay at least so the target is a kinematic body I hope it's still walking so you can see now it's taking steel the target because we are asking for a target type and not a kinematic body type so this is perfectly fine and now what I'm going to do is in the trigger box box instead of mouse enter it I'm going to connect the body and through it function so when you remove that and I'm going to connect the signal with body entry on this script on body entry and the on body entered function except it expects an object that is the body the other body that interacted with it so this should be fine and this is a string and here somebody some body we're going to log the other bodies like this I'm going to save and I'm going to launch the scene and everything should be fine you can see that the kinematic body is being triggered each time I'm entering in the body okay you have another goose function on body exits third I think I think it's pretty exited you can always check here put it x0 and on body XE and now I can play I have a signal sent when the kinematic body enter it and when it exited somebody exited okay so that's pretty cool so now what we are going to do is we are going to change the material of the cube and in order to do this we will have to store the material information of this mesh instance but before that we are going to add in the material section and new let's add a new shader material like this and we are going to add for now no you know what let's do let's still do I'm going to clear let's still do a special material like this for now we are going to work with shaders a bit later the only thing I need to do is to enable transparency on this so I'm going to go in the flags and I'm going to say transparent like this so it's going to be transparent as soon as the body enters and I think I can use shadow not shadow to opacity but I think I can use hmm no I cannot use shadows with with this subject right now okay so the only thing I'm going to do is to tone down the opacity when the body enters okay so what I need to do and in this case is I need to grab a reference of this material of the trigger box material so I'm going to expose using export and notepad to the mesh instance let's call it BOTS and this will be a mesh instance and in the very function I'm going to say box is equal to this node that is a machinist ins at the pass box back then I'm going to grab the material mats on this box I'm going to say mat equals to the Box Tops matter dot material but get material over right so it's the material override directly and I'm going to say that when we enter the body I'm going to say the material we are going to set a property on top of it and the property you can look at them in the directly in the inspector so in this case its albedo color so I'm going to to save a color so I'm going to create two colors in my scripts one is going to be solid color and the other is going to be transparent color the first one is going to be a new color of type with one everywhere so white and the Alpha is going to be full and the transparent color it's going to be white but the opacity is going to be zero from 2f because it's afloat okay so I have two colors so I'm going to set the albedo cold or to the solid color to the transparent color when the body enters I'm going to set when the body exited the solid color back okay so let's test this out however of course the trio burbs needs to know the box path so I'm going to put the mesh instance in the path make sense and this is not working why because I have an error I think I didn't have the chance to get the material there if you go to the material tab here you need to grab the mesh first I think so box top mesh that night so let's get the surface material I think that zero because you can have multiple materials here it's the zero the zeroth one that we want to take it's probably going to be fine now it's not going to be fine and you can see that it's not happy with the way I'm changing the property sheet reference not sets to an instance of an object so it's probably that this is boiled is null sorry so we are going to say mat and we're going to debug like this so now you're going to see the real debugging process I'm going to cancel that disc so the material is already false already no sorry so I'm going just to close all the script in the script panel because sometimes it's annoying it's always opening so I don't want so I'm going to close all and discard this and why can't I get Matthew off the surface of the surface so much top natural fish get surface material going to do this instead and to see if it works at least I should have to match okay so now it's it's getting the surface material and as you can see it's working perfectly fine the only thing I had to know to do is to get of course the surface material this was a bit this was a bit tricky because in this case I had to make sure that the material was not no so in this case it's working fine I'm happy with this so I told you that in the player that's not the right in the target so it's not the right way to to do the movement and again I think it's still the case so what I'm going to show you is the proper way and the proper way is to use the actual physics processing it is because physics process works with the actual physics engine and is a fixed frame rate and in this case I finished 16 godo by default and what we want to do is because we are kinematic body we want to use the kinematic body functions that actually does things behind the scenes so what we are what we are going to do is we are going to store the to get the inputs in the physic process like this we're going to put the direction like there like this here and instead of moving the transform in the physics process we are going to comment this or even return or delete the function and here what we want to do is we want to use the move the move and collide function or moving slide function let's use moving slide so as you can see moving slide this metal this method moves the body along a vector if the body collides with another it will slide along the other but the e rather than stopping immediately that that's pretty cool in fact it's if you want to make a like a platformer or something like this you can like use the Move and slide and it will do the it will ultimately automatically calculate the velocity that will need be needed that will be returned when you entered another body so that's pretty a pretty nice feature it's very analogous to the character control law you have immunity okay so the the velocity that we are going to do to send for now its direction and you shouldn't I think times this with that that time it's written here you should not multiply it by Delta the physics engine handles applying the this velocity directly then why do you need to do in order to make this function working fine is to say what's the up direction so you can work with the slopes so we are going to say that its vector field at up in this case and then you you have different options do you want to stop on the on the slopes do you or do you want to slide do you want to - how many how many slides are available I think slides is how many time how many slopes you you can be in order to to slide exact riser so you have different option you're welcome to look in the documentation to have more details about this and as you can see moving slides also gives you back a velocity and while you can do with this is instead of like putting direction directly but you can do is you can calculate the velocity like this determining its going to be attacked or three and you can say something like this something like this and here instead of moving directly to instead of changing directly the direction at line directly the direction as the velocity you can add the direction to the velocity and the move inside function is going to return you the calculation needed for the collision in the velocities so it's going to be integrated probably properly the next time you go in the physics process so now that you play that you can play this you can see that I'm now adding a direction to my velocity so one thing that I can do it is to do not always increase the the velocity is I can so basically while you can do to make it you you can dump the the direction let me think about this so yes in our case we can just directly apply to the direction like this and the return will be for any checks further along the process but in this case we don't have any anything to say about this but one thing that we can do for in addition to this is we can add gravity so plus equal gravity I think in this case we need to add the Delta time because we are changing the velocity so gravity equals let's say nine point nine point eight and that is going to to work but the thing that is not going to work fine as that the floor needs to be a static body so I'm going to change the type of the to a static body meaning a body that can be static so I'm first going to add a static body like this and I'm going to add the floor as its child and I'm going to add collision shape like this that is going to be a box I'm going to extend the box using the neat tool like this and I'm going to play to see if my character is not falling through the ground okay so it's not working that well why all yes because we are cancelling the velocity time so let me let me do this let me remove the first to transform the the input translation so it's not working great because probably I've inverted the gravity heads to these instead okay so now I have something that is staying down on the floor which is pretty okay I think in order to show you the concept I will also add all your static bodies in the scene so I'm going to add a studied body I'm going to add a mesh instance so you can see it it's going to be a cube well let's let's put a cylinder it's going to be there now it should slide the slide function we are going to add it poison shape this collection shape will be a cylinder like this and I'm going to put the collision the cylinder like this here I'm going to save and I'm going to add back for now plus equal the the direction times the speed we have a speed yes we're on the speed and I think I need you here time it with Delta time I think so even though it's not to play no it shouldn't be this because it's already being multiplied and so here the gravity is being multiplied by the time because it's the acceleration so it's okay but here the full velocity at the end is going to be multiplied by Delta time inside a moving slide function so it's it's going to be okay so here I should be able to as you can see add my speed but probably a shoe I should have to it's it's it's confusing me in the fact that the documentation is saying not to not to multiply by Delta time because community I will multiply by it at the time but you can see the nice behavior here and I'm using an a constant velocity so I have no friction so it's always moving but you can see the nice behavior of the of the the ball when it's sliding along the the cylinder so let's add friction so friction is the is in the opposite direction of the velocity gravity oh let me rename this instead of breaking the road gravity we are going to export it you know what we are professionals whoa we are going to export also the friction see is open fiber things it's going to be fine and we are going to remove friction or CT minus equal at the end - I called the friction times equals re friction time's up that's it - friction so it's basically no sorry manual sequel the velocity cannot be normalized times minus friction that's how it should be so basically it's a force that is going in the opposite direction so I don't need the minus here of the velocity so it should be fine let's see so it's not fine physics I think it's because I'm getting pretty tired because it's starting to be a long video tutorial and I need a bit more wake up at the end I need to do pose some poses I've done only once during the full recording okay so now I have got friction that is working pretty well so as you can see it's also working pretty well there everything I need it's going to D it's going to be in the opposite direction of the velocity okay perfect I think I need to apply this before godo is sending me back the new velocity and know after it's okay it's okay after and I'm going to lower down the friction coefficient and you can see it's working perfectly so now I have like a small overboard bull and I'm Priya people--but one thing that I can do too is now I'm going to show you how to add a bit of UI we are going to show a bit of shaders to and then and I will call it down don't okay even though there are tons of other stuffs to see in in good so in order to add some you I I'm going to go in the 2d part of the good organ engine and I'm going to add in my scene even though it's a 3d scene a control node so a control node is the base class for anything related to UI so I can add the control node like this and I will go in the layout panel here and I will click on full rect and as you can see it will be taking the full space available in my UI in my viewport sorry so this node for me is going to be whi rich colored UI and I'm going to add a stack of buttons okay so to do this as you can see this is and I'm really loving this and go to when you select a node that is a three node that's going in 3d and when I'm selecting a 2d node or you I know it's going in 2d mode this is working like a charm so in the UI node I'm going to add a child and I'm going to add what we call the vertical box so I'm going to say V box container and this container is going to contain objects that cut that are going to stack up vertically so what I'm going to do is then add a button like this and as you can see it's not big enough so I'm going to scale it a bit like this and I'm going to in the layout make it left wide like this and it's going to like immunity make sure that this object is always being scaled according to the height of the viewport if you want you can even select the the the small green pin like this and you can untap them so they always are related to the viewport okay so if I'm doing this it's always going to take this space relative to the viewport so as you can see I've added a button let's call it say hi and as you can see we have a say hi button and the cool thing is that now we can press control D and you can see that the button are going to stack up in this vertical box container okay so we are going to just add three buttons and what I want to do is on the UI I'm going to add what we call the theme and the theme is going to propagate down to all the control components control nodes that are the child of the node that is receiving the theme so we are going to go in the theme section here we are going to create a new theme and if you click theme you can see that you can have different like in CSS you can have different theme for different UI components so in edit theme we are going to add a new item and this is going to be not a new item so when we are going to add a class item and this is going to be the button I'm going to click on add all and you can see that now in the field that I'm going to say by the way as a resource so I'm going to click Save here type in the cool thing with this is that now I'm going to move it in art and the cool thing with this is that now I can edit it edited right there so I'm double clicking here you can see that I have the button yeah and in the bottom what I can do is I can go in the for instance I can go in the color and I can change the font color but I can also change the style and the style is going to be normal and I'm going to add let's say flat box you can see that it changed it changes color so now I have the choice of picking a color for my button so I'm going to pick a purple color for instance you can see that also I have the border width so if I want to have a border I can also have the corner radius I'm going to add five pixel in order to make them wonder and I also have the expand margin you can see that you can expand the size bottom and height without modifying the layout we can add a shadow if we want to let's add a small shadow if an offset let's say 2 pixels and 2 pixels down we are going to maybe just only 1 it's going to be cool we are going to make it less transparent you can also have expand margin which is we saw that already so this one we can have until they accelerate so but but for now we are going to stay with this maybe the we are going to maybe change the color to a nicer looking color like this and the cool thing too is that we can change also in the UI the theme here we can change the font size so as you can see the button is not changing when we are over any offering it so what we can do is we can save this style box as Viji box for instance as a new resource and the cool thing is that now I can put tbg box in the UI I can put the BG box in every every part of the button so now you can see now it's not moving anymore so what I want to do now is in the V box container I will go in the size flag not size block in the rect and I will try to change the overall size so it's not here sorry it's in the groove Direction nodes in the marching node margin is just adding a marching but it's in the touring I've lost my way around I mean sighs some what's its separation so I'm going to add separation and here as you can see I can change the the the separation between the content of my vertical box which is pretty cool and in the in the three buttons that I've here I'm going to select them and I'm going to go in the in the crowd in the rect sorry and I'm going to set their minimum size to 50 pixel now it's too much 30 pixels and now I have a button that is a bit wider higher sorry and in the container I can also add in the margin can add 10 pixel on every part so in this case in the bottom is minus 10 in the write as minus 10 and in the left is plus them so if I'm running the game you will see that I will have a UI on top of everything which is pretty cool and I can flick on it on my button and what I will do now is I will connect the behavior of those button on unfortunates basically okay so in order to do this what I will have to do so that the first button is going to say hi the second button is going to let's say change change something or maybe I'm just going to show you for one button and we'll get them to logic so this guitar is not going to be dead long even though it's not true but I'm just going to show the process for one button okay so the first button what we are going to do is we are going to add a script in the source section called button script I know I got an idea of something that we can do we can make we can we can spoon objects and yes let's do let's do this let's do this object spawning so I'm going to create this button script so it's not good button I'm going to change the name let's call it and spawn so I'm going to go back in the solution so you can see I have button here I can safely delete it because it's not in the solution anymore I can go in the spawn button here and what I will do is hear it from the button because it's a button and in the ready function it will connect the signal that is button down or press here that lets go red button now with a method on this place something like so now if I'm Elaine click on this button you will see if I'm putting the spawn script on this button I'm going also to change the name of this spawn rigidbody because it's what it's going to do it failed because I deleted the button that C sharp file and it's still in the cs5 the CG profile this is something that is a bit annoying in go-to now with c-sharp this is something that you will have to to work your way around usually what I'm doing is I'm rebuilding and cleaning the solution and also I'm closing in reopening below so I will do this off-screen so I will launch todo and now my issue is come ok I have my script on it and if I'm launching the game by clicking this button you can see it's hooked up it has hooked up the event one thing that this strange is that the box is by default transparent and it's by default transparent because it's called joining with it's detecting the collision with the ground which is another body so in this case what I want to do is make the box a bit higher the trigger box higher not colliding with the ground okay this was pretty logical so now what I want to do is to spawn physics objects that I'm going to create so I'm going to create a new scene by clicking this plus button and I'm going to add a root node which is going to be let's see physics pops I'm going to change the type to to a body and this is going to be a rigidbody um a body that is going to be able to move and I'm going to add a mesh instance with a box inside and I'm going to add inside the physics body ecology that represents the box I'm going to save this scene as TM TM as a new prefab like it's not a prefab that is just the same and back in the main scene in the button I will expose a new field and this new field is going to be what we call the packs attacks see and one thing to note is that export you can have the primitive types and you can have note path and you also can have packed scene which represents a scene that you can instantiate in good ok so what I'm going to do here is I'm going to when I'm clicking I'm going to instantiate the Box the scene actually so in order to do this I'm going to say physics boxing dot instance that is going to give me an instance back of the scene and I'm going to cast it as as a rigid body to reach it by hardly roll this which is giving me back a note but I'm going to say trust me it's a rigid body so here for instance I can say the rigid body position because rigid body is a special I can also an access to the global transform but you know for a quick and easy dirty word direct each one's from work I'm going to use the translate function that is going to offset my rigid body at the beginning and I'm going to offset it as at a new position which is going to be run down on top of the on top of the scene on x and y so I'm going to say Gigi got random range between minus 10 min 10 this is giving me a double so I need to cast it back to a float I'm going to do the same on Z so I hope you see what I'm doing here it's pretty easy in fact I'm going to first instantiate the scene cast it as a rigid body and I'm translating the rigid body because rigid body is a special I have access to the transform okay and if I want I can also add our video to add force and I can add a random force one since let's create a random force what's wrong with this Oh something like this and I'm going to add redundant force and I think the value for a random force should be a bit higher so I'm going to to do something like this I'm adding the random force at the position of the rigid body so RB or rigid got got translation if I want that represent translation that represents the position of the object okay now I have this button that when I build and don't run expect a scene and this scene is stored in the prefab okay so I'm going to drag it there and it should instantiate randomly this cube and adding it to the scene so I'm not seeing it and by the way one thing that you can do in Godot is you can go in the remote option here that is going to show you the actual tree of your scene okay of the build if you want it's a way to connect the xyx the the exist existing tree of the scene and displaying it there it's not the local tree but it's the tree of the of the game that is being played and I don't see my cubes so one thing that I've met bond here is that is that I didn't attach the the object to the scene so we'll need to attach it so what I'm going to do is I'm going to get the tree and I'm going to get the root node of the the scene which is going to be probably nicing and I'm going to say add child I'm going to add this rigid body as a child okay and now I'm going to play I see all my cubes being added but not in the middle of the of the scene this is not an issue I just need to know I'm just going to try and save this slide to see the values of the transform so here are the usual it's there okay - - four - five okay so I have a range of five so I'm going to say - five - five - five - five four now I'm going to not put I'm going to disable the the running force and as you can see it works and also one thing that I've made wrong is that it's as it starts at zero it will probably start at ten and I'm also going to change the signs of the optic cube which is a bit big I'm going to put two and five zero and five zero point five I have to do the same thing for the collision shape well it's the extent so it's your it's half this because its extent just half of the cube it's going to look a bit nicer we will see so it's a bit high okay but anyway it's working and one thing that I want to show you that you may know if you're good or user is that I can click on this button here and I can link the camera of my editor with the scene this is pretty cool now if I'm rotating around you can see so it's better if you have a dual screen or you can use the windows left and right button to dock them like this but you can see that it's a way to link the the editor view with the with the game so if I'm putting this on my second monitor I can totally see the motions being synced okay so it's a good way to overcome the fact that the editor is not fully linked with with the game okay so my button is working I can add my voice back and what I'm going to put it at five I can have my force back and usually this initiation should be in the the in the script attached on the scene it's not good practice but it's just to show you how it works you can see it I have a random force being applied it's maybe a bit too much and you have also you have led to add a torque torque is a angular force if you want to but you can also add a central force which only takes a force and not the position which is better in our case we're going to remove a bit of magnitude for the force and I don't know if you can see it but yes a force is being applied on some cube okay so that that's pretty cool you know how to spoon objects which is a fundamental thing in game development and another thing that I want to show you is how to be raycast you go to you can recast in two different ways I'm going to show you one of them and the other one will be straightforward if you follow the documentation and I'm going to on the target note I'm going to add a node which is a raycast and this is pretty cool because in Godot you can see some you can see your red your red cast I'm going to enable my red cast and you can see that this recast here exists in the scene okay so I can place it and I can of course connects signals with this recast and and detective it has collide it has collided with something and the cool thing is that you can say exclude my parent to the raycast detection okay so this is pretty cool because now it will ignore my it will ignore my collision detect my my Collider so let's say that I'm going to implement raycast for the ground I'm going to in the player I'm going to add a simple in the input I'm going to add a new input which is going to be done I'm going to add a key which space okay close I'm going to say here in the target which is country which is in fact later I'm going to say yeah if inputs that get action like just is action just pressed which is another method that the Texas reaction was just pressed before in the previous frame what I'm going to do because I'm going to save velocity but y equals to jump speed we are going to expose supports loads and speed and to say ten perfect and now I should have implemented the basic jump a basic jump system in my targets I'm going to lower down the jump speed to five perfect you can see that it's working fine and miracast here is going to be minus one on the ground it's just for an example of course you wouldn't do things like this you will use is grounded method or property inside this but it's just for the sake of this example I'm going to make the red past a bit lower - your point - sorry 0.3 yes and I'm going to grab this red a red guest I'm going to call it round rapist and in the and the function just to show you another way to get an object by name I'm going to show you how to get it by name so I'm going to say rate a strand read ask and here I'm going to say in the ready function I'm going to say ground right class equals kept mode of type ray cast cold and here I can directly put a stream and the stream is going to be bound ray cast so here no mistake allowed you need to have the right name otherwise you will have an error and you can see that the node path is actually a string so here I should have my red cast that is being enabled meaning it's going to trigger some things and here in the physical process after I can say if my ground ray cast that is colliding I can say Chile got prints and I'm going to say if my ray cast is not colliding I'm going to say my character is in here okay truth ward usually I prefer to expose note that but you can see that when I mean error it's shooting the it's showing the debug and while and and and if I'm not in the air it's not shooting it so there's a way to do Ray casts in guru of course you have all the ways to shoot ray cast you can call the physics server you know which you add your ray cast I'm not going to show you that because it's well explained in the documentation but I just want to show you that you can have access to a gas using notes which is something that I'm liking a lot in Google because you can actually design your real gas in a very precise way so as you can see we have a lot of different needed feature I will say for basic game development the last thing I wanted to show you is how to create shaders in guru or at least a kickstart for showing you how to create ur so what I want to do is I want to create a wobbly ball here so I'm going to go in the physics in the player scene and I'm going to create from scratch a rake shader for this bowl so I'm not going to now use a spacial material I'm going to create my own material not using node but using shader language close to GLSL so I'm going to click clear here and I'm going to add a new shader material I'm going to click here and I'm going to create a new shader and that is going to when I'm clicking on it expose an editor where I can write code for my shader the first thing I will need to say to Godot is that the type of the shredder is a spatial being that it's going to be a 3d material applied on the 3d material ok I'm going to say that I have a vertex shader where I can have access to the position of the vertices the normals and things that are sent to the vertex shader and I am going to add the fragment shader which is responsible for modifying the fragment or the pixel of the shader if you are not familiar with Scherer at all note that I cannot explain really fast what a shader is but basically a shader is a program that is being executed for every vertex of every that are being added to the mesh and for every pixels you have the vertex the fragment shader that is being executed so even though here we are telling we are seeing both shaders at once you know you need to know that you have the vertex shader and the fragment shader okay so in the vertex shader we are going to manipulate the vertices of the object and a vertex is in our case because it's a spatial material it's the position of the vertex the normal of the vertex the vertex color if we have some the UVs etc and in the fragment we are going to deal with the color of the pixel of the object okay so in the vertex shader what I want to do is to manipulate the vertices that are being represented if I am going to show you the wireframe I want to manipulate the vertices here of the vertex of the after of them of my sphere so what I want to do is to first know how to modify those vertices so you have a macro called vertex a con sensory that you can manipulate and this vertex I can for instance say I want to say plus equal to the normal times a value so let's say 2.0 you will see that it will push along the normals my vertices and this is quite cool because this is the start of something that I want okay so now let's say that instead of pushing two units I want to push with the sign and I have a variable called time in in Godot and this is pushing the vertices between minus one and one toward the normal okay so of course I can add something like 0.1 here to scale it between 0.10.0 one and one and I kind of so of course add a bigger time value so you can see that here the shading language is pretty strict it needs not an int but a float so unique you add point zero five and now you can see that my blob is starting to pulse which is pretty cool because this is what I've what I want so now what I can do on top of that as I can expose those parameters using what we call uniforms so I'm going to say uniform this is going to be a float this is gonna be going to be time factor and I'm going to duplicate the time fact the uniform and I'm going to say scale factor so here I can use time factor and here I can use scale factor and in the mesh on the shader here you have now shade of parents and I can say for instance I've won five and I want let's say I want to yeah and you can see that I can control the scale of my shader each time I'm modifying them starting back the shader it's like sending and sending the parameters back to the shader but let's say I want 0.1 I want to fast be like 10 I can make my shape and I blog my blog post like this and I have exposed parameters that I can modify using a script if I want a c-sharp script if I want okay so now what I want to do is I'm going to add a texture so I'm going to say uniform some 30 V and this is going to be a nice texture so now you can see that I have a new slot for adding a texture so I'm going to create a procedural texture using the noise texture and this is going to be a seamless texture and if you click here once and going the noise and add a new open simplex noise and you click here once you will see a preview of the noise so now what I what I want to do is I want to create a float before modifying my vertex that will corresponds to the noise so I'm going to call that noise and I'm going to say texture and I'm going to sample in the noise with the UVs and this is not good enough because it expects a float so and the cool thing is that if you know shader languages you knows about Swizzle and here I'm going to say I want the R value of the of the texture so basically this is getting the pixel and the texture at UV coordinates that we are getting from the vertex the vertices and we want the R value so the red value and only R gives me a black and white value so the noise is going to equal to B equal to a noise value so what I want to do now is to tie my scale factor by the noise and times and it's not going to be very very expressive here so I'm going to scale it and as you can see we're starting to have a bit of noise there but it's very how can I say it's very [Music] it's it's not that much contrasted so what we can do in order to do this is just for now the scalp like three times the noise so we're going to put it back there noise so I'm going to scale down the noise to 0.5 and what we are going to do is we are going to make the UVs and move with the time a bit later but I want to tweak my noise so you can see that if you tweak the noise we have different effects something like this is better I think I'm going to scale down the texture no need to be a high texture like this and I am going to add another uniform noise strength which is going to be a float and which is going to time so now with the noise strength I can add the noise but as you can see it's taken into account of course in the pulsating and the pulsing motion which is quite normal but what I can do here is [Music] I can do why we call the clamp meaning that I don't want this value to be higher than zero so what I can do is I can clamp everything between zero and one and and sorry and the angle and and let's say 10 points so you can see that it scales neighbors never goes below zero and always and never goes higher than 10 okay and I can also if you want make it higher than the noise and now I have a parameter here that corresponds to the notes the noise strength that will go that will explode a bit like this and I'm pretty sure it never it will never go higher than this and of course this is just an example to show you how you can go about a shader like this but note that while you are changing the vertices you are not changing the normal so you will have to change the normals I don't want to go that far because it's not a shade of course I just wanted to show you an introduction to how you can go about making cool stuff like this using the shader language of kuru I just want to show you that if you we want to expose a color we can also add a GUI form here that we read that will be effect for RGB a factor for I'm going to call add video one sense and I'm going to add the hint color which will give me a color picker in the shade of parameters but albedo is is a value that we want as a factor of three so we are going to say RGB dot RGB and you can see that now I have a picture here and I can change the color like this making it red again and I can say also I want the Alpha and the Alpha is stored in the value of this vector so this vector for as a value and then you can see that now I have the alpha working because I'm storing it in the Alpha you also add the roughness so I'm going to uniform flows roughness I'm going to add the roughness and say it's equal to the roughness of this material and as you can see the roughness is Mac I can change it like this because I've passed the roughness here to the roughness of the vertex the vertex okay so I think that we're going to stop there trying to think about something that I've missed you we didn't covered animation sound and thing like this but now that you know your way around the engine you're pretty up and running I think you will be able to to work fine or at least starting projects and the the rest of your journey I will say will be on the go to forums on the on the discord in the community in the documentation which is really really well-written I think because always you always have examples or always you often have examples we didn't cover particle systems really well we didn't cover networking which is pretty cool another two so yes we didn't cover it importing meshes but those are things that if you're a programmer a game developer you will quickly find I think I still hope you have get the most of this tutorial we have ramped up the the difficulty along all the tutorials I hope you you will still be able to to to understand everything that I'm saying if you are coming from a unity or Unreal background you'll probably understand the vast majority of it if you have any questions don't hesitate to put a question in the comments what can I say I hope you enjoyed this tutorial and I will see you around in the next video thanks again have a nice day [Music]
Info
Channel: sociamix
Views: 12,821
Rating: undefined out of 5
Keywords: godot, godot game engine, game development, game programming, unity, unreal engine, ue4, C#, programming, course, unity godot, tutorial, introduction, transition, learning, open-source, blender, 3D
Id: owYm18IarYU
Channel Id: undefined
Length: 215min 14sec (12914 seconds)
Published: Sat Jun 20 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.