How to make Hill Climb Racing in Godot

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Very cool, I love it.

๐Ÿ‘๏ธŽ︎ 5 ๐Ÿ‘ค๏ธŽ︎ u/Kaligule ๐Ÿ“…๏ธŽ︎ Sep 23 2021 ๐Ÿ—ซ︎ replies

Excellent. Well explained and easy to follow.

๐Ÿ‘๏ธŽ︎ 3 ๐Ÿ‘ค๏ธŽ︎ u/myclykaon ๐Ÿ“…๏ธŽ︎ Sep 23 2021 ๐Ÿ—ซ︎ replies
Captions
there are probably quite a few of you who have fond memories of playing hill climb racing in high school for those who don't know hill climb racing is a game in which you control a physics-based car and you try to get as far as you can in this video we're going to be having a look at how you can recreate the basics of that game inside of kido we'll have a look at how you can create the car how you can set up the terrain and how you can add things like coins and fuel sounds good now let's get started showing for this tutorial i've created an asset pack which includes all the basic things that you need like textures for the terrain a car a character fuel and coins i've also added some extra stuff like a second character different car color and three types of wheels you can get these assets by going to the link in the description and then on the page scroll all the way down you can support me by paying for the assets but you can also just grab them for free so now let's set up the project i have this empty project right here i'm going to go to project project settings and then i'm going to scroll down to the rendering tab in here i'm going to click environment let's pick a color for our sky going to go with a bit of a light blue there we go and then let's go into display window and let's set the size of our game to 1920 by 1080 and then the test width and height let's set that to 1280 by 720 so and then let's go under the stretch mode and then set it to 2d and for aspect ratio let's keep the height so the width can change the height of the game will stay the same now let's import the assets by right clicking here and then opening file manager and let's just drag in the two folders there we go and now let's let's okay import them and now we have an audio folder and a folder with all the sprites now let's make that car let's add another note and let's search for richard's body gonna add a 2d rigid body and let's call it player let's immediately just add it to a group so let's go to the note tab the groups tab and then let's add it to the player group this will be useful later now let's add a sprite and this will be the car sprite let's go back to the inspector and in the sprites let's drag in the car there we go let's also add the collision shape for this we're going to be using a collision polygon 2d and now you can tell your collision shape i usually like to add a bit of a rounded corner so it gets stuck less often now let's add some wheels let's open up a new scene and click on other node we're going to make another rigid body and let's call this wheel we also need to put this in a player group so there we go and then let's add a sprite and let's go to the inspector and what kind of oil shall we make let's just go for the small one there we go and now on the rigid body let's also add a collision shape and let's make that a circle let's make it fit and there we go now we have a wheel let's hit save and let's create a new folder call it scenes and let's save our wheel in there now let's add the wheels to the car to connect the wheels to the car we're going to be using a pin joint so let's add a pin joint 2d and let's call its wheel holder then we're going to be connecting node a to the player so the car itself and then to this we're going to connect the wheel so let's go into scenes and then we'll let's drag it under there let's go back to the wheel or the pin joint and let's connect node b to the wheel there we go and now we can move the pin joint into place but now it appears in front of the car so we can move it up here so it appears behind let's move it over in place there we go and now you can hit ctrl d to duplicate it and then you can move it you can hold shift while moving to keep the same height and there we go so now i have the wheels on the car let's save the car into the scenes folder and save it as player here we go next let's create a little scene to test our car on for that let's create a new scene and let's create a node 2d let's call it level one to that we're going to add a static body 2d this will be the terrain for now we'll replace it later and to that let's add a collision polygon 2d for reference let's first add the car so let's go into the scenes folder and drag in a player and the player is really big as you can see so let's zoom out quite a bit and on the collision polygon let's draw a little simple terrain shape let's go down and all the way over here here here and let's close it up and there we go let's save it now let's save it in a new folder called levels here we go and let's save it up if we now run this you will see that the corner is in the top there so we'll need to add a camera let's simply do that so on the player let's add a camera 2d it's centered on the player right now but we will improve the camera in a moment we now run this oh whoops we need to go on the camera and then sets current hey let's forget that whoops uh as you can see you can't see really see anything of the train so let's close it again let's go into debug and then enable visible collision shapes when i run this you can see the train you'll see that the car falls really slowly let's tweak the gravity a little bit now let's go back to our player scene and let's select the rigid body let's tweak the gravity skill you can mess around this year with this yourself and see what you like but for maya messing around 30 seems about right let's test this out and see it falls a lot faster let's move our player up a little new yeah seems about right we also need to tweak this on the wheels so let's go on the wheel rigid body and let's change the gravity scale to 30. and oop you can see it falls a lot faster and you can see the wheels are also turning but the suspension is not really looking nice well there is no suspension so let's change that let's go into your player scene and select the wheel holders you can select them by holding ctrl we're going to tweak the softness that's to turn this up to about two and a half and if we test this there you go it now bounces a little or well it uses the quote-unquote suspension um now it's finally time for some programming so on our player let's add a script and let's move it to a new uh let's just call it code new code folder and let's save the player script in there i like to change the template to empty or no comments let's hit create let's create a new variable which we will call wheels in here we're going to store all the wheels we're going to apply a force to you can make only the back tire spin but we're going for a 4-wheel drive or well in this case a 2-wheel drive now let's grab all the wheels and put them in the wheels array to do this we are going to search for all the wheels within the wheel group oh whoops we forgot to put the wheel in the wheels group so let's go to the wheel rigid body the node groups and let's add it to real group and let's save it now let's add some player input shall we in the physics process we're going to add an if statement checking if the right arrow key is pressed then we need to loop over all the wheels to add a force to each single one to add a force we're going to be using the apply torque impulse function then let's add a new variable called speed this will be how much force we will apply to the wheels torque needs to be a really high number so let's go for 60 000 then let's add it in the impulse function let's also multiply it by delta to account for frame drops but since delta time is a really small number let's multiply it by the physics frame rate which is 60. so if we then run this and then press the right arrow key no it works yay at the moment though the player can go faster and faster until the damping on the wheels stops them from going faster so let's add a simple limit on how fast the player can go let's add a new variable called max speed and let's set it to 50. this value is a lot lower because it's a different type of value we're dealing with this is angular velocity let's add a check per wheel if the angular velocity of the wheel exceeds the max speed now that we've added that we can add the input to go backwards let's just do this via good old copy and paste let's change the input to ui left and let's check if it doesn't exceed minus max speed and let's apply a force of negative speed so let's now run it see if it works so okay we can move forward and we press the other arrow key yay we can move both ways okay now let's just do something about this awful camera angle in the level scene let's select the camera and let's go into offset if we tweak this you can see we can offset the camera but only by a little bit to make this range bigger we need to change the drag margin and then to the left but we can't visualize this right now so let's go into editor and draw drag margin so now we can see it if we then tweak the drag margin on the left and increase this you can see that this range is much bigger let's set it to about here and then let's also tweak the zoom let's zoom out a little so let's say 1.7 maybe makes it really big uh let's tweak the offset again a little bit there we go let's test this out okay that is already so much better now that we finished the basic functionality of our car it is time to add the terrain i already have a 20 minutes in-depth tutorial on how to create curved terrain in godot so i won't be going into much detail in this video so just follow along with what i do and you'll be fine let's go to the asset library and then let's search for smart shape and let's install smart shape 2d here we go let's hit install and hit install again and there we go we now hit ok a new folder should appear called add-ons with our rm smart shape which is smart shape 2d now we need to enable the plugin so let's go into project project settings and let's go to the plugins tab here is smart shape td let's hit enable there we go and if we now go back to our scene we can add if we hit ctrl a we can scroll down and add a smart shape but the icons don't appear because we have to restart godot but thanks to editing magic i already have them so now let's add an ss to the shape closed let's hit create and then first let's just get rid of our old terrain and then on the shape let's first add a background texture so we can see the shape in the images folder there is a drain folder with a dirt background texture but first we need to go into the shape material let's open it up and in the fill textures array we need to increase its size to one and then let's drag in the dirt background texture now we can draw the shape but the toolbar doesn't appear so to fix that we can deselect it and then select the node again and the option should appear let's select the first tool let's make a massive rectangle and so but as you can see the texture only repeats once so we need to go in to the dirt texture with that selected let's go to the import tab then under flags you have the repeat property and let's set that to enabled let's also immediately do that for the grass texture let's set it to enabled and hit re-import if we then go back to the shape we can select the second tool to add points along the line you can drag it up and you can add some hills you can right click to remove a point [Music] so let's just create some hills so we have some hills we can add some curvature with the same tool still selected you can hold shift and then drag on a point to create curvature there you go and there we go we have now a basic we now have a basic terrain now let's add the grass texture on top of the dirt to do this let's go into the edge meta materials to avoid confusion let's close up the fill textures in the edge metamaterials array let's also increase it to 1. then in the first slot we need to select an edge metamaterial so we need to scroll all the way down until we see accessory material edge metadata let's click that and if we open that up you'll see a bunch of properties like the z index and the range on which the materials should appear to add the textures we need to add add an edgy material so once again we need to scroll down down down down until we see access to the material edge [Music] and we when we open it up um we need to increase the textures array let's increase it to one and now we can drag in the grass texture to make the grass appear we need to move one of the points and then it shows up so the shapes updates yay now we've got some grass and it looks pretty nice okay um now we need to add a collider to add a collider all we need to do is hit the collider button up here with your shape selected and now it generates a collision shape or while a collision polygon as you can see and collision should work so now let's just run our game shall we it works yay okay as you can see the wheels appear behind the grass and i kind of prefer to them to appear um in front of the grass so let's move this static body up here and oh that fixes it hey okay now let's also just go into debug and disable visible collision shapes again and let's also move our car a little bit more to the start of the level so let's select it and let's put it over here okay now that we've finished the terrain let's move on to adding coins for the coin let's create a new scene let's create a new scene up here and then let's click other node for this we're going to add a area and then we're going to add an area 2d node let's rename this to going and to this let's add a sprite let's hit create and then let's go into the images folder and then the pickups folder there are a bunch of different coins and let's drag one of the coins into the texture slot so now we have a coin let's also add a collision shape to the area collection shape 2d and let's change it to a circle shape 2d let's increase its size so it fits the queen and now we're going to add some code to the coin on the coin let's add a new script and let's save it in the code folder use this and let's hit create then let's start off by adding a variable for the value of the coin we're going to be using an export variable so you can reuse the script for coins with different values now we need to connect a signal of when the coin is picked up so let's click on the coin and then go to node and in the signals let's uh where is it body entered let's double click on that and let's connect it to the coin itself we hit connect a new function appeared now we'll need to check if the body that the coin is colliding with is part of the player we'll do that by checking if the body is in the player group now we will need a place to store how much coins the player has collected but first let's save this scene and let's go let's save the coin scene in the scenes folder hit save and then let's go to the level and on the root note let's add a script let's call it level manager and let's pick the code folder to save it okay and then let's hit create now let's add a variable for how much coins the player has collected and then let's add a function to add new coins to the total coins collected i will take in the value of the coin and it will add it to the total coins collected so it's more of a score this might not be the best name but eh just let's just roll with it let's go back to our coin script and in there let's grab the root note of the current scene which is the node that our level manager script is attached to and on that note let's call the add coins function and we will pass in the value of the collected coin let's add a pickup animation for the coin on our coin let's add an animation player it's create and on the animation player window let's get animation new and let's call it pick up now we're going to animate the position of the sprites and the opacity of the sprite so let's go back to the inspector to the transform and let's hit the key icon right here and let's take use bezier curves when we hit create it'll create two new tracks the x position and the y position we're only gonna move it upwards so let's just delete the track for the x position then let's go about here and let's insert a new key and let's make it go up so that is minus y so let's say about 30 pixels up and that is way too slow so let's move it over let's also make it go a little bit higher so minus 60 or so okay now let's tweak the earth a little to make it go faster in the beginning and slower uh near the end let's scroll to zoom out and let's grab the bezier handle of the first point and let's move it downwards so it's a curve like this now it looks like this let's change the opacity of the sprite so let's click on sprite again let's go into visibility and then modulate let's key the modulate and also use bezier curves um we're only going to animate the alpha so let's delete the r g and b values so this is a value of one and here we want it invisible so let's add a new key let's click on it and let's set it to zero and as you can see it disappears but it doesn't really suit the upward movement of the coin so let's also go into this curve and let's zoom in and let's tweak it so the curve looks similar to the other curve nice okay now we have that done let's go out of here and let's move the playhead back and on the coin let's add an audio stream player not an audio stream player 2d because that has a position we just wanted to play uh sort of in the center on both speakers equally so let's use an audio stream player and let's go let's pick up with a capital p of course because i want to be neat um any animation let's add an audio playback track and let's select the pickup audio player now let's go into the audio folder and let's drag in the con audio file as you can hear it now makes a sound yay now we will need to initiate the pickup animation via code so let's go back to a script on a coin and under here let's grab the animation player and play the pickup animation we also need to disable the collision shape while the animation is playing to prevent it from being picked up multiple times we're going to do this by using the set the third method on the collision shape set the third basically lets you do a calculation after all the physics calculations have happened so there won't be any physics calculations on the disabled collision shape let's also delete the coin after the animation is finished to do that let's click on the coin go to node and in the signals oh no we need to go to the animation player and then in its signals there is an animation finished signal let's double click it connect it to the coin and in here we'll just simply say q3 now it's time to test it out now let's go to the level one scene and in here let's add some coins uh they are in the scenes folder and let's just drag in the coin scene let's duplicate it a couple times and move it over let's see if it works hopefully it does let's run it and we then drive forward the animation and the sound plays nice okay now let's add a ui for the coins and have a little indicator of how much coin you've collected so far to do that let's create a new scene and let's make the root node a canvas layer let's rename it to ui and unlike ui let's add a texture rectangle and then in your images folder and pickups let's drag in coin sprite so if we zoom out the blue line is our screen and this is our icon so it's it's pretty big but if we try to resize it it won't work so we have to check expand then you can resize it and by holding shift you can scale it uniformly let's make it about this let's put it over there now let's also add a counter well first let's rename this to point and then for the counter let's add a label let's move that over but the font is absolutely tiny let's type in a zero here it's really tiny so let's add a custom font i will put a link in the description to a font called fredoca fredoka if you scroll down then here is a button to download the truetype font file let's download it and let's drag it into a project there there it is so on our label let's scroll down to [Music] custom fonts and let's tick that then let's create a new dynamic font and then in the font property let's drag in hey there we go but now it's really small so let's go into settings and let's change the size to ah 60 64. something like that and let's add an outline let's increase the outline size and then the outline color let's change it to black a little big area something like that nice oh that turning on the filter also really helps as you can see okay now we have that let's hit save and let's save our scene in the scenes folder and let's just save it as ui now let's add the ui to our level or to our game let's go into the scenes folder and let's drag in the ui under the root node over level then let's go into the script and in the level manager script we'll need to get a reference to the label and then we will set the text of the label to a string version of the coins collected variable and then now let's run it if we run into the coins you'll see that the score rule gets added we've added another feature nice and let's add another one let's get started with the fuel mechanic in the scenes folder we're going to duplicate the coin scene let's hit duplicate and let's call it fuel then let's open it up and let's switch out the sprite for the fuel let's go into images pickups and then drag in the fuel let's also change the collision shape to a square one rectangle shape 2d and let's resize it to ma roughly match the size of the fuel and let's also change the sound of the pickup let's delete the old sound and let's go into the audio folder and let's drag in the fuel sound effect let's check it to start okay now we have that done the animation should still work nice we will need to add a script let's remove the old script and let's add a new one and let's save it in the code folder as fuel.gd let's hit create oh and it also might be a good idea to rename the root note to fuel let's go back to the script and let's delete the ready function and then let's go to node and in the signals you can also already see that it still has the old coin body connected let's disconnect all let's hit ok and let's reconnect it to the fuel and then let's remove those extra spaces let's go into the coin and let's copy this part and then let's paste it let's remove this line because this will add a coin value here we will need to add a function on that we need to call on the player to tell the player that fuel has been picked up and it needs to be refueled but we don't have fuel on our player yet so let's go into the player script and then let's add a new variable called fuel and let's set it to 100 so let's start the game with full fuel then let's add a function and let's call it refuel and in here we're just going to say fuel is 100. so the fuel gets reset when the fuel is picked up now we need to call this function from the fuel pickup in there we will get the root note of the current scene and we'll search for the child with the name player and on that we will call the refuel function i will search for the root node of the level so make sure that the player is a child of the level 1 node we will all on the fuel we will also need to reconnect the animation player and an animation finished signal so let's disconnect the old one and let's reconnect it to the fuel hits connect and then we'll want to delete it again q3 now we'll need to implement the rest of the functionality in the player so let's go to your player script and then let's create a new function we'll use this to deplete the fuel let's call it use fuel and we will need a copy of delta we will decrease the fuel by 10 times delta and you can make the number smaller or bigger depending on how fast you want to deplete the fuel then we will also clamp the fuel variable between 0 and 100 so it doesn't go outside of that range now let's make it so that the fuel depletes when the player tries to go forward or backwards it's also stop the player from moving when the fuel is depleted select all the input functionality and then you can hit tab to indent it let's add a quick print statement at the bottom of our physics process to check how much fuel we have left and now let's test this shall we okay at the bottom you'll see that it's 100 and then we press forward it will decrease and if we just keep using fuel go time to 40 30 10. if it's hit zero i'm pressing keys but nothing happens nice let's also test if our fuel pickups are working so in a level scene let's go back into the scripts the scenes folder and let's drag in the fuel scene and let's run it we then drive into the fuel as you can see it goes back to 100. it's working yeah now it's time to add a ui indicator for how much fuel you have left in our ui scene let's select the coin and let's move it down a little to make room for the fuel then on our root node let's add a texture rectangle let's rename it to fuel and in there let's drag the fuel icon there we go it's really big so let's scale it down let's enable expand and let's go oops make it about this yeah that seems about right and then under fuel sprite let's add a rope press progress bar not a texture progress but a progress bar and let's move that over here and let's scale it up as you can see it shows the percentage but let's just get rid of that let's go into the percent drop down and let's disable it so in all these values you can see it has a min and a max value which is perfect for fuel because it goes from 0 to 100 and then the value we're going to change is literally called value if we change this to 50 you'll see that it's halfway full filled but there is one problem it's ugly so let's fix that let's go into the custom styles and then let's enable background and then let's add a style box flat let's change it to a little bit of a darker gray and then let's go into [Music] border and let's change the border to black then border width we will want to change that to let's see then for the border width let's change that to 6 6 6 and 6. you can see it's added a border then let's change the corner radius let's change that to 10 10 10 and whoops and 10. and we added nice rounded corners which looks pretty good and then let's also change the expand margin because now it's the foreground goes over the borders so as you can see if we increase this oh whoops this one is over here you can see that it increases for now let's just set this to 6 6 6 and 6 and you will see why in a moment okay now let's move on to the foreground let's enable it let's just close this one for now and let's add a style box flat let's change this one into a nice green color and then let's go into corner radius and let's change that to [Music] f 5 5 5 and 5 for every corner as you can see it's also not added some pretty neat looking rounded corners then let's add a little highlight at the top in border let's change the color to a completely white color and then in border width on the top let's add a little line there we go that looks pretty nice now if we zoom in a little you can still see it overlaps a little so let's tweak the values a little bit let's close the foreground and let's open the background up again and then the expand margin let's increase it to seven seven and seven ah that looks nicer there we go now let's add some code to make it actually function we'll need to add a new function to our level manager script so let's do that shall we let's call the function update fuel ui and it's passing a value to which the progress bar needs to change now let's get a reference to the progress bar we'll need to open up the level 1 scene for the autocomplete to work and there we go now it works on the progress bar let's change its value to the value that's passed into the function let's also change the color of the progress bar depending on how much fuel you have to left that let's get a reference to the green style box then on the background of the style box let's linear interpolate the hue in the color picker if you click on the hue saturation value button you can see that the hue is about 1 3 filled if we slide this around you will see that it goes from 0 to 359 but in code these values range from 0 to 1 which is a float value so what we need is from 0 to about 1 3 which is 0.3 now let's do that we will lurp it from 0 to 0.3 and we'll lurp it by the value which is the fuel in the end which is value from 1 to 100 but we'll need a decimal value so let's divide it by 100 we will need to call this function from the player so let's let's go in there then let's scroll down to the refuel function and let's call the function in there we need to get a reference to the rules note of the game scene but since this is just a child of that root node we can just say get parent and on there we can just call the date fuel ui function and we'll pass in the fuel value then we can copy and paste it over here so it also gets updated when the fuel gets used and when the fuel gets reviewed it's also good to copy and paste it and put it in the ready function so the progress bar shows the correct value when the game starts now let's see if it's working let's run the game and then if we drive around you'll see that the bar depletes when we drive whoops if we keep driving and driving you'll see that it keeps depleting and will turn to a red color and if it's fully depleted you can't drive the car anymore it's working nice now let's add a simple game over stage shall we in the player scene let's click on the player and let's add a timer node and let's call it a game over timer and then it's properties let's turn on one shot let's set it to about five seconds not 55 and then let's go into the node and then signals and let's double click on timeout let's connect it to the player we'll come back to this in a moment let's scroll back up so with this if statement we're checking if the player has run out of fuel and if it hasn't then the player can still move but if it has let's add an else statement and then we're gonna check if the timer is not already running and if not we're gonna start the timer that if statements will prevent it from starting continuously so then up here we will add a gameovertimer.stop every frame the player has fuel we're going to stop the timer and we'll start the timer once the player has run out but if the player rolls down into a fuel and has fuel again we're gonna stop the timer again so the gameovertimer timeout function or signal will only be called once the player has gone for without fuel for 5 seconds so this is basically our game over state in here for now we're just going to say get tree dot reload current scene but this is the place where you can add your own logic for when the game or when the player goes game over let's test it so if we keep driving the car back and forth until we run a run out of fuel we ran out of fuel and we've rolled back into a fuel pickup and we can keep going if we then try this again if we run out of fuel and then we have five seconds and then the game will restart nice now that's working let's add some improvements to the car let's start with adding a character in the player scene let's first add a sprite for the little guy's body let's add a sprite and let's go into images and then characters and then you can pick blue or the red character let's go for the blue one and then let's oh let's switch over to the inspector and then let's drag in the body sprite it appears in front of the car so let's first move it up here and then let's move it behind the car sprite so it appears behind then we will need to add another rigid body so let's add it rigid body there we go let's rename it to head then to this let's also add a sprite and let's drag in the head sprite and we'll also need to add to add a coalition shape and let's add a circle collision shape about this then let's grab the head and let's move it over so i kind of want to have the head appear between the body sprites and the car sprite so let's move it between there and there we go we move this over you can see it's in between and then we'll need to add some physics joints so let's hit ctrl a and let's add a pin joint this will be the head spring if we then test this and then move around you'll see that the head is really quite heavy and sometimes does flips like that let's make it a little lighter we can on the headspring we can loosen it a bit by increasing the softness and on the head rigid body we can decrease its mass if we then run it you'll see that it is bouncy and wobbly but a whole lot less if we then land on our heads you'll see that it also snaps sort of and then bounces back but what we can also do is kill the player when it lands on its neck just like in he'll climb racing let's do that oh oh i almost forgot one thing is also important to set is if you want your player to be able to slam their head into coins and fuel to pick them up we will also need to add the head rigid body to the player group so let's go into the players in the into the groups tab and let's hit player yeah okay let's continue in the player script we'll need to add a new variable let's call it dead for when the player breaks their neck let's start it all over as false then we'll scroll down here and let's remove the old sprint statement then we add an if statement checking if the local rotation compared to the car of the head is more than 90 degrees or less than minus 90 degrees also check if the player is not already dead and then we'll just say that dead equals true because the player snapped their neck nozzle on the head spring joint let's set node b to an empty string basically clearing it out this way the head can rotate freely then up here we also check if the player is not dead so they can only move when they're alive this way the timer also gets started so in 5 seconds after the player dies the game also gets restarted 4 we can test this though we need to change the collision layer on the player you can do that by going on the player and then into the collision drop down and then changing the bit to the second bit i also need to do this on the head but we're going to change this one to the third one this way the head and the car chassis won't collide with each other and if you don't do this it it's gonna be pretty glitchy now in the game if he lands on the character's head and it rotates more than 90 degrees it will snap and the game will be restarted after 5 seconds now let's add some improvements to various things in the game the first thing we are going to add is air control which is actually really easy to add all you have to do is go into the input code and in there you will add an apply torque impulse function apply a force of minus 6000 and we will multiply it by delta and we'll multiply that by 60. then let's copy and paste this line to the other backwards input and let's change the minus 6000 to 2000 and now you will be able to do front flips and flips while holding the forward or backwards key in the air next up let's add the engine sound effect so on the player let's add a new node and let's make it an audio stream player let's call it engine sound fx and then let's go into the audio folder and let's drag in the engine sound you can click on the preview to preview it and what we want to do is change the pitch skill when the player is driving from 1 to about 2 also don't forget to enable auto play then let's go into the code and we will need to add a new variable to check if the player is driving or not let's create a variable called driving and we'll initialize it as 0. then in both the input if statements let's say driving plus equals 1. let's reset the value of reframe by adding driving equals 0 at the top of the physics process then at the bottom of the physics process let's add an if statement checking if driving equals one so driving will be zero when no input is pressed driving will be one if either one of the driving keys is pressed the driving will be 2 if both the inputs are pressed so only when one of the driving keys is pressed this code will execute then in that if statement let's change the pitch skill of the engine sound effect to a linear interpolation of the pitch skill to two and we will do that by a speed of two times delta you can change this however you want and then if the player is not driving we will linear interpolate it back down to one [Music] well that's pretty much self-explanatory it's working another bug that's currently in there is that if you hold both driving buttons at the same time if you will deplete really fast to fix that let's remove the use fuel function from the driving input and let's move it to the is driving statement another good thing to know is that you can change the friction of the wheel and the bounciness if you go on the wheel and then the physics material override you can create a new physics material and here you can change a bunch of properties like the friction and the bounce if we turn that's all the way up and save it let's run it the car will be super bouncy now let's let's add a little alarm icon for when the player has run out of fuel to do that let's on the fuel let's add a new texture rectangle let's rename it to alarm and in there let's go into images other and then let's drag in the alarm texture let's move it over to here and let's maybe maybe turn on expand and let's scale it down a little bit there we go now on the fuel let's add an animation player let's hit create and in the animation player let's create a new animation called idle this is for when the player has enough fuel in there we'll go on the alarm and then in visibility and i'll modulate and click use better curves and hit create then we'll remove the rg and b values and we only mod modify the modulates alpha then let's go into animation it duplicates then we have a copy and then let's hit rename to alarm and here we will go forward and then we will insert the key and we'll make it invisible or rather we'll move this one to the end this one is a value of one and then you will click on this one and then hit right click here and then duplicate keys so we have a value of zero here again we then play you'll see that it it blinks let's hit this button to make it loop and then we need to call this function or well this animation from the code oh whoops i almost forgot something on the idle animation that has to be zero not one else we can constantly see the icon we now move this it's invisible okay now let's add the code all we have to do is go into the level manager script and then under here in the update fuel ui function let's check if the value that gets passed into the function which is the fuel is equal to zero so if the player doesn't have fuel we will play the alarm animation on the animation player and if the player does have fuel we will play the idle animation and hide the alarm icon if we then test it and run our fuel you'll see that the alarm animation plays if you want you can also add an alarm sound effect as you can see we just picked up three coins of five but we got 20 points that's a bug i know it's as well recording and let's also fix that while we're at it so that is a book that gets introduced when multiple body parts like the head the car is not really body part but also the car picks up a coin at the same time i thought i'd fix this with the disabling the collision shapes but apparently it happens within the same physics frame so this gets set at the end of physics frame to fix it we're going to add a new variable called picked up and then in the if statement we'll check if it's not already picked up and when it's picked up we will set picked up to true and this should fix it so you've reached the last chapter of this tutorial in this last chapter we'll add some nice parallax backgrounds to your level so let's do that shall we on the level let's add a vera lex background note and to that let's add a parallax layer and to that let's add a sprite just a regular sprite and in the sprites let's go into images other and then let's drag in the clouds texture you can see it's right here on the sprite let's also go into the offset and disable centered so the center point is on the top left okay now let's tweak the parallax layer parameters let's go into motion and let's set these values to 0.2 and 0.2 then on the mirroring let's set it to 3 000 on the x-axis so mirror it's that's the width of the image and it will repeat it after uh 3000 pixels we can't really see it so let's move it a little bit up like this you can hold shift to move it along an axis there you go that looks nice and then let's hit ctrl d on the parallax layer and let's go into the sprites of that one let's drag in the background let's rearrange the order because uh we want the green background to appear behind the clouds and then on this sprite let's move it oh wrong one this one let's move it down to about here then on the new parallax layer let's go into motion and let's make it move a little slower so let's set it to 0.1 there we go and i think that's about it let's test it shall we now the green background moves the slowest and the clouds move at a medium speed well that was it you finished the entire tutorial good job now it's up to you to add new features and make it into an actual game you can turn it into something similar to hill climb racing you can also go with completely different direction for example you can make it a racing game make it split screen or you can add guns like in the game or to die another fun thing you can do with how we set up the car is that you can just duplicate the wheel holders and the coat will just work for all the wheels well that was it i really hope you learned something and i would love to do some more videos like this recreating games inside of godot i was thinking of maybe doing something like recreating angry birds or doodle jump leave your suggestions in the comments down below of which games you would like to see recreated inside of cadell well that was it for today i am going to bed properly and i hope to see you next time goodbye you
Info
Channel: LucyLavend
Views: 13,637
Rating: undefined out of 5
Keywords: hill climb racing, hill climb, hill climb racing android, Phisics car game, Godot, godot 3.3, tutorial, coins, fuel, godot coin tutorial, SmartShape2D, Physics joints, Godot game, hill climb racing 2, hill climb racing game, Lucy lavend, lucy lavender, lucylavender
Id: nPX9MrnvNLo
Channel Id: undefined
Length: 65min 38sec (3938 seconds)
Published: Tue Sep 21 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.