Making a Simple Game in Unity – Bugs – Unity C# Tutorial (Part 12) HD 2017 [w/ subs]



00:00:00 – sent from awful Mediacom and this is
00:00:02 – part 12 or something of the making a
00:00:05 – simple game in unity tutorial series now
00:00:10 – in this part we're going to be looking
00:00:12 – at fixing a couple of issues that we
00:00:14 – have with the game those issues are one
00:00:18 – when you run into a wall such as this
00:00:21 – one right here and I'm pushing forward
00:00:23 – and I'm ultimately push into the right
00:00:24 – notice we don't even move well sometimes
00:00:27 – I do move and it I mean there's nothing
00:00:32 – wrong with that right so the issue here
00:00:35 – is we can we can fix this with a physic
00:00:39 – material that is different from the
00:00:41 – ground material will make two different
00:00:43 – ones I think we'll try that and see what
00:00:45 – the problem is i believe is i'm forcing
00:00:48 – the player forward right and there is a
00:00:50 – wall there and it is telling me how you
00:00:52 – can't go this way but i'll keep forcing
00:00:54 – it that way and so it's just pushing the
00:00:56 – player against it and then pushing to
00:00:59 – the left and to the right obviously that
00:01:01 – will cause some some friction and
00:01:03 – especially when you're working in a
00:01:05 – physics engine that is fairly competent
00:01:07 – that does work that way now I wouldn't
00:01:10 – say this is a realistic result of how
00:01:13 – physics would be applied in the world
00:01:15 – but it's doing it for us so we have to
00:01:18 – work around it and one way I'm going to
00:01:20 – do that and when trying to do that at
00:01:21 – least I've not tried this method yet so
00:01:24 – but it's the only one I could think of
00:01:25 – so we want to give it a shot I'm going
00:01:27 – to make to physic materials the first
00:01:29 – one will be for the ground so I'm like I
00:01:31 – ground the two and then I'm gonna make a
00:01:34 – wall material now the ground one is
00:01:36 – going to be the same and I'll make sure
00:01:38 – that is applied me uncheck the play
00:01:41 – there I'm gonna apply that to the ground
00:01:43 – and in the wall material Wow and then a
00:01:46 – wall wall material one thing we're going
00:01:48 – to change is the friction combined I
00:01:51 – want to set that down to minimum and
00:01:54 – then I'm going to apply this to that
00:01:57 – node and now if everything's fine we
00:02:00 – should now be able to walk while being
00:02:02 – forced against it there we go now I'm
00:02:05 – walking while being a forced against it
00:02:07 – this is my normal speed well it's hard
00:02:10 – to normal speed someone must be almost
00:02:14 – speed still kind of slowing me down
00:02:18 – isn't it a little bitter is hmm I guess
00:02:32 – that would work for us for now but the
00:02:33 – swing is down a little bit but as a
00:02:39 – comparison let me run into this wall
00:02:41 – over here and to show you how much
00:02:42 – better this is ok so that was before and
00:02:45 – this is now so big big difference maybe
00:02:50 – not be a complete fix and then it'd be a
00:02:52 – fixed at all but it is it makes this not
00:02:56 – seem completely broken which is fine
00:02:58 – with me for now now really quick this
00:03:01 – game is pretty much done with for the
00:03:04 – series at least those games pretty much
00:03:05 – done I want to move on to other things
00:03:08 – but unity different games different
00:03:10 – things so I'm just doing this to kind of
00:03:13 – fix a couple of the big standing issues
00:03:15 – and to get it a to a better point where
00:03:18 – i can say yeah I'm okay with that being
00:03:20 – done so this is one of those things the
00:03:22 – next thing is if you notice if I was to
00:03:25 – come out into an open space and I select
00:03:28 – my player in the hierarchy you can see
00:03:30 – over here my x y and z notice the y
00:03:33 – however is is mana it's just changing
00:03:37 – with me just sitting here and that's
00:03:39 – because gravity is being forced on me no
00:03:41 – matter if I'm on the ground or not and
00:03:43 – this is causing the physics in physics
00:03:45 – to be kind of a little crazy and the
00:03:48 – gravity is applied to me right now
00:03:50 – sitting in this chair right but it
00:03:53 – doesn't seem it doesn't work as well in
00:03:56 – akin a game rolled apparently I don't
00:03:58 – know it's just anything with unity but
00:04:00 – one thing this causes for us for
00:04:03 – whatever reason is if I move to the left
00:04:04 – and to the right notice I am moving on
00:04:07 – the X and the Z and I should not be
00:04:09 – moving on the X and the Z moving up and
00:04:12 – down also moving on the X and the Z but
00:04:17 – if i uncheck gravity
00:04:19 – on the left and the right just my Z is
00:04:22 – moving on my ex so clearly this issue is
00:04:25 – stemming from that gravity thing right
00:04:28 – so gravity being applied to me while on
00:04:30 – the ground is causing the issue so how
00:04:33 – do I fix that well it's going to be just
00:04:35 – a workaround I think I don't know if we
00:04:37 – caused the issue or if the issue is just
00:04:39 – something that is there and we have to
00:04:41 – always work around it one thing i want
00:04:43 – to do those i'm going to check to see
00:04:45 – when i am on the ground and when I am
00:04:47 – make gravity be 0 and when I'm not
00:04:51 – applying gravity so when we can blend
00:04:54 – blood we couldn't do that is we can send
00:04:56 – array from our player downward and if it
00:05:01 – hits the floor stomp the players gravity
00:05:04 – so we can limit the distance of the
00:05:06 – array so array is like a little laser
00:05:10 – okay it's gonna be going from point A to
00:05:12 – point B or in our case from point A
00:05:15 – towards a direction for a certain
00:05:17 – distance and this is going to be good
00:05:20 – for us because we can send a ray allen
00:05:22 – is it and then detect what it hits and
00:05:25 – where it hits and when it hits or
00:05:27 – whatever so this is good for us because
00:05:30 – I can send it down and if I hit
00:05:32 – something that is the collider down
00:05:33 – there then I will stop the players
00:05:36 – gravity that way whenever we're on the
00:05:38 – floor no gravity will be applied when
00:05:41 – we're off the floor gravity will be
00:05:44 – applied and that seems to be the best
00:05:46 – way to go about doing this so I'm going
00:05:47 – to hop in here and go ahead and start
00:05:49 – riding that up the beautiful thing about
00:05:52 – this is it's going to be super simple
00:05:54 – for us to do now we've worked with an
00:05:56 – inline if statement before right and it
00:05:59 – was super easy one thing I'm going to do
00:06:01 – is we want to go through the physics
00:06:03 – class and we're going to go to the
00:06:06 – gravity there's physics and you have
00:06:08 – gravity right now gravity is a vector3
00:06:11 – so you have x y&z you can have gravity
00:06:14 – on your ex on your wine and on your Z
00:06:16 – but in a game mold likers hers like ours
00:06:20 – we only have gravity huh on the y which
00:06:23 – is pushing us downwards so is a negative
00:06:25 – value on the Y pushing our player
00:06:27 – downward so we need to set a new vector3
00:06:30 – for this and I could do that by saying
00:06:32 – new vector
00:06:33 – three as at being setting that equal to
00:06:34 – but one thing when I do and we're going
00:06:37 – to do an if check to see if our ray hits
00:06:41 – the floor and one way we can do that is
00:06:43 – within our inline if statement again
00:06:46 – then thus afford it may look confusing
00:06:47 – so make sure you go back to that part
00:06:49 – where did we do an inline and i'm
00:06:54 – curious now where do we do an inline i'm
00:06:57 – saying we did one where i explained it
00:07:00 – there but i am not seeing one it's
00:07:08 – nothing there nothing in the player I'll
00:07:12 – here it is so we have Kendall level
00:07:15 – equal to level the load is less than so
00:07:17 – we're doing and condition here we're
00:07:19 – comparing these two that would return a
00:07:21 – bowling saying if that is true make it
00:07:25 – true that is false make it phones so
00:07:26 – this will be another example of that so
00:07:29 – the bullying we're going to be having to
00:07:31 – return though is the raycast so the
00:07:34 – raycast will turn return true or false
00:07:36 – based on if it hit something or not if
00:07:39 – it hits something it comes back true if
00:07:41 – it did not hit anything comes back false
00:07:43 – obviously and one thing you can do with
00:07:45 – great cast that we're not going to be
00:07:46 – doing is set up a hit variable or an
00:07:50 – information variable that would give you
00:07:52 – the information of the object to hit
00:07:54 – such as the coordinates of the object
00:07:56 – the any information you want any
00:07:58 – component you can grab you can get
00:08:00 – information from so if you hit the
00:08:02 – object you know the object but we don't
00:08:05 – need that information all we need to
00:08:06 – know is if we hit something or not so to
00:08:09 – do that we're just going to be turn
00:08:10 – we're going to go through the physics
00:08:11 – class go to the raycast method and
00:08:15 – recast is going to return true or false
00:08:18 – for us and the first thing the perimeter
00:08:22 – we're going to need is the position the
00:08:24 – race starts at notice there's a lot of
00:08:26 – options here 12 total parameter sets
00:08:30 – that we could use we're going to be
00:08:31 – looking for yeah the origin direction
00:08:33 – and distance so the origin is to
00:08:36 – transform position so we want to come
00:08:39 – from the player the player class is
00:08:41 – attached to the player object therefore
00:08:43 – the transformed opposition in this class
00:08:46 – would be the position of the player next
00:08:49 – need a direction so the direction would
00:08:52 – be down right so how do we get down well
00:08:56 – we could do a new vector3 and then say
00:08:59 – down will be 0 and the negative one on
00:09:02 – the Y and then 0 so that will be in the
00:09:04 – downward direction cause negative 1y why
00:09:07 – is up and down and the negative would be
00:09:10 – in the lower half of the axes so that
00:09:13 – would be down but there's already a
00:09:15 – setup there's only something set up that
00:09:16 – we can go through then go through the
00:09:18 – vector 3 and then go dot down and that
00:09:20 – would give us the exact same result 0
00:09:22 – negative 10 when there's also there's
00:09:26 – also one for up there's also one for
00:09:27 – back there's one for forward there's you
00:09:32 – know we can go through the vector 3 and
00:09:34 – grab all these different values that are
00:09:35 – already predefined for you when you need
00:09:38 – a direction so that it's good for us we
00:09:40 – can do vector 3 dot down and now we need
00:09:43 – a distance so we know our cube was one
00:09:48 – unit cubed right so there's it's it's
00:09:51 – one unit in unity I believe is one unit
00:09:53 – was it to know it's one and then we
00:09:56 – scaled it down to looks like right here
00:09:58 – at point six so we need about point six
00:10:02 – for the distance just a rough thing for
00:10:05 – now so we have our bulleen check there
00:10:09 – and then we need to set up values that
00:10:12 – it can be equal to know what I did there
00:10:13 – so the first one is if it is true i
00:10:16 – won't gravity to be zero so i could do
00:10:19 – physics or not physics of gravity where
00:10:21 – they have the physics on gravity
00:10:22 – variable there so i can set it to vector
00:10:25 – 30 and that does the same thing that
00:10:28 – vector 3 Don down does it gives us a
00:10:30 – predefined value which is 0 0 0 again we
00:10:34 – could do new vector 3000 no reason to
00:10:38 – that we already have it set up for us
00:10:39 – else if that is not true if that raycast
00:10:44 – does not hit anything I want to apply
00:10:46 – the same gravity that we apply
00:10:48 – everywhere else which i think is a bit
00:10:50 – low anyway but for now we'll just keep
00:10:53 – it the same I think it's like point nine
00:10:55 – so we'll do 0 negative point
00:10:58 – 94.9 5f and then zero so that is all
00:11:08 – this should take me see if I wrote that
00:11:09 – right of course I did not write it right
00:11:13 – what about put using ground and recast
00:11:21 – oh we need to actually close that
00:11:27 – raycast there the parenthesis that is a
00:11:31 – method right here and all these
00:11:32 – parameters good within that method and
00:11:33 – this is just part of the if statement so
00:11:36 – doesn't that don't even up to be inside
00:11:38 – that uncheck play no errors go back into
00:11:41 – play and yeah not pointing on fine by
00:11:47 – the way I had to write the first time I
00:11:48 – did it yeah that was a stupid thing to
00:11:50 – do point there 9.5 is the correct
00:11:54 – variable or a correct value so we fall
00:11:57 – to the ground and they notice we come to
00:11:58 – a weird stuff but that's fine now when I
00:12:01 – move to the left and the right the
00:12:02 – gravity is not being applied so we're
00:12:04 – not going crazy but notice we're not the
00:12:07 – same y position than we were before that
00:12:08 – means we're probably floating above the
00:12:10 – floor a little bit um no big deal though
00:12:13 – right we can just shorten the length of
00:12:17 – the ray so we'll do a point 45 I'm just
00:12:25 – putting random numbers and there and
00:12:26 – hoping it works right so now we're at
00:12:28 – the exact same value we were before when
00:12:31 – it was dropping down to point zero to
00:12:33 – nine and point zero three and it should
00:12:35 – still work left to right up down okay
00:12:38 – notice though that we're floating a bit
00:12:40 – more because gravity is not being
00:12:42 – applied to us now they were on the floor
00:12:44 – and that's the thing well on the floor
00:12:47 – gravity is forcing us down into the
00:12:49 – ground the same way gravity or our force
00:12:51 – from our movement forces us into the
00:12:54 – walls and then slows us down when
00:12:56 – wherever we're walking into the walls
00:12:57 – the same thing happens on the floor so
00:12:59 – now that that's not happening we're
00:13:02 – sliding a lot more than we were before
00:13:03 – so I can up the drag to about eight and
00:13:07 – that should give us about what we want
00:13:09 – or
00:13:10 – what I want don't know what you want
00:13:11 – probably a bit slow now I don't really
00:13:15 – know I remember how fast it were before
00:13:16 – but I mean all that's up to you you know
00:13:18 – just if you want to modify the speed no
00:13:21 – problem just change a single value which
00:13:24 – I can go ahead and do I guess make it
00:13:26 – seventy doing all this in play mode so
00:13:28 – it's not going to save but that's fine
00:13:31 – 70 and then eight so that seems to our
00:13:39 – foot slowly to the ground I do want to
00:13:42 – go to edit project settings physicist
00:13:46 – player physics player physics and then I
00:13:49 – want to let uncheck have we done right
00:13:55 – that's the one what was it just messing
00:13:57 – around with something I don't know okay
00:13:59 – so i won't be why the gravity on the Y
00:14:02 – to be kind of powerful like a point or
00:14:05 – not point keep saying point negative 25
00:14:07 – and then want to set the to that in here
00:14:11 – as well whenever we start the game we
00:14:14 – could grab the value of the gravity at
00:14:17 – the start and then use that to set it
00:14:21 – back there but if you want to do that if
00:14:22 – you want to make this game something
00:14:23 – more please go ahead and do that but I'm
00:14:25 – not going to worry too much about it
00:14:26 – followed it faster everything's still
00:14:28 – fine but one if I was to come off the
00:14:31 – ground does it set itself doesn't add
00:14:34 – gravity to me yes it does so there we go
00:14:36 – so if I was to fall off the floor that
00:14:40 – would still apply so we just did all
00:14:42 – this in the world select right so if you
00:14:44 – wanted to do this in your actual levels
00:14:47 – please make sure you do that but I'm not
00:14:49 – too worried about the game coming up
00:14:52 – becoming a complete game I'm not care
00:14:53 – about the levels i don't care about any
00:14:55 – of that stuff I just wanted to teach
00:14:56 – some stuff and this video was just to
00:14:59 – fix a few things that I didn't do
00:15:01 – properly and there's still a few things
00:15:03 – I didn't do properly I'm sure but I
00:15:06 – wanted to get these out of the way
00:15:07 – before you move on to a different game
00:15:09 – but moving on a different game does not
00:15:11 – mean i don't want to ever come back to
00:15:13 – this and do a few more things so don't
00:15:16 – don't be afraid to leave me some
00:15:18 – suggestions down in the comments I will
00:15:20 – get to those and
00:15:21 – and see what I think about them but I
00:15:25 – posted a video yesterday then asked you
00:15:28 – guys want you want me to do next right
00:15:31 – the platformer series won the pole but
00:15:34 – as a few of you have pointed out in
00:15:36 – different ways there are plenty of
00:15:39 – platformer tutorials based in unity
00:15:42 – actually on YouTube and I don't want to
00:15:46 – just be another one of those really i
00:15:47 – mean i could probably do one it's a bit
00:15:49 – different but i just don't want to I
00:15:51 – don't know I want to do something that
00:15:53 – not many people have done if any and one
00:15:56 – of those things that came up that was
00:15:57 – really interesting to me was a runner
00:16:01 – game kind of like temple run we have a
00:16:04 – track now that your player automatically
00:16:06 – runs on and then all you have to do is
00:16:08 – dodge obstacles jump duck stuff like
00:16:10 – that and if you hit an obstacle then you
00:16:13 – lose or you go back a certain distance
00:16:15 – or something like that it'd be an
00:16:18 – interesting thing to do we probably
00:16:19 – wouldn't do it based on a path we'd
00:16:21 – probably do it we're running down like a
00:16:23 – like a straight street or something none
00:16:26 – it not any curves or anything but just
00:16:28 – random obstacles throughout the street
00:16:31 – that you have to dodge left to right
00:16:32 – duck under and jump over we could do
00:16:35 – that I also had a suggestion for a 2d
00:16:38 – RPG again there's a bunch of these games
00:16:40 – out there but there's not many or if any
00:16:43 – unity tutorials based on a 2d RPG and
00:16:46 – ours be pretty simple we would have a
00:16:49 – hack and slash combat system with very
00:16:52 – very simple mobs or monsters in the
00:16:56 – world that would chase the player down
00:16:57 – in the way right so they wouldn't really
00:16:59 – path find but they would see the player
00:17:02 – and try to get to and would do that and
00:17:04 – we'd have a very simple inventory system
00:17:06 – and now an inventory system is something
00:17:09 – that it can be very complex and I've
00:17:11 – wanted to get to that for a while
00:17:14 – because that is like the most requested
00:17:16 – thing then I have seen I mean I get
00:17:20 – messages for that and I don't get
00:17:22 – messages for a lot of stuff that are
00:17:24 – suggestions I'd be great if I did but
00:17:25 – when I do get a message for something
00:17:27 – it's how to do either how to do
00:17:29 – minecraft or how to do an inventory for
00:17:32 – an RPG point again
00:17:35 – so I want to do a simple RPG with a
00:17:38 – simple inventory and a simple combat
00:17:40 – system and then work from there and then
00:17:42 – I already have an inventory system that
00:17:44 – i made i will start working on it a
00:17:47 – little over a month ago and i was going
00:17:49 – to do this inventory system and then
00:17:51 – release it for you guys to play around
00:17:53 – with the news and if you want that let
00:17:55 – me know but if you if you want to learn
00:17:57 – how to do it then I would suggest voting
00:18:00 – it wasn't really a vote but commenting
00:18:02 – and let me know you wonder the RPG or if
00:18:04 – you're interested in the runner let me
00:18:06 – know we can do that we could do it for
00:18:07 – mobile maybe I don't how to work with me
00:18:10 – testing on a mobile device maybe I can
00:18:11 – just I don't know we'll just figure out
00:18:13 – something and when else was there
00:18:17 – suggested mmm so much a couple people
00:18:21 – want the platformer and I understand
00:18:22 – that not everybody likes the platformer
00:18:26 – tutorials that are already out there
00:18:27 – some of them are just not very good low
00:18:29 – quality and you know people not too
00:18:35 – great so let me know what you want ah I
00:18:39 – want to do what you guys want because
00:18:41 – the only reason not do these videos or
00:18:42 – the only people that watch these videos
00:18:44 – are you guys obviously so I want to do
00:18:48 – what the majority of you want to see I'm
00:18:50 – not going to be able to do something
00:18:51 – that everybody wants but i wont to do
00:18:55 – something with the majority of you want
00:18:56 – and if I can do something that the
00:18:59 – majority of you guys want plus other
00:19:01 – people that don't watch me want and
00:19:03 – they'll come in and watch and that'd be
00:19:05 – great for the channel and great for the
00:19:06 – website because speaking of that I need
00:19:10 – people on the forum i have i have this
00:19:15 – was one guy that it's very dedicated to
00:19:17 – this it seems like and I really
00:19:19 – appreciate what he's doing that he's
00:19:20 – he's in posting on the forum knowing and
00:19:23 – nobody is going to come by and talk to
00:19:25 – him and it's just kind of it it sucks
00:19:27 – for me and it sucks for him because I
00:19:29 – want this to happen but people have to
00:19:32 – come and he's trying really hard to get
00:19:35 – people to come and and have a place to
00:19:37 – discuss things I know there's plenty of
00:19:39 – other forums out there but I want a
00:19:41 – place where we can discuss things that
00:19:42 – we do on the channel I can get feedback
00:19:45 – and questions and answers and stuff like
00:19:47 – that so I'm going
00:19:49 – people from this channel if you do like
00:19:51 – my videos and you leave comments and
00:19:53 – stuff just go sign up on the website and
00:19:55 – then it's it's not like it cost anything
00:19:57 – and there's a single ad there's one ad i
00:20:00 – hears every one had i think there's one
00:20:04 – ad on the whole website so it's not like
00:20:07 – i'm i'm asking you guys to do this for
00:20:09 – money I want to get a community started
00:20:11 – over there and it's it's it's going
00:20:14 – slowly but there's one guy who I can't
00:20:17 – remember his name but I can see his icon
00:20:19 – is is really being helpful I really
00:20:22 – appreciate it so if you're watching
00:20:23 – thank you person that's it for this
00:20:28 – video let me know in the comments below
00:20:29 – what you want to see platformer I can do
00:20:34 – that the 2d RPG we can go over a basic
00:20:37 – one and the runner series would be kind
00:20:40 – of cool against not really see any of
00:20:42 – those on YouTube might be some that who
00:20:44 – knows yeah we'll see thanks for watching
00:20:49 – guys follow me on twitter and all from
00:20:50 – india follow me on Google+ awful media
00:20:52 – check out the website and the forum


Video Url:
http://youtu.be/sOB4_5jAWcs

Comments

comments