Unity code

Hi, I’m currently working through a Udemy course and I am trying to wrap my head around how this piece of code works.

I have two scripts, both applied to the player and it moves when I press the WASD buttons but I don’t know how it does this. Here are the scripts.


Could you kindly explain to me how it works. Thank you!

Hi,

Which course are you currently following? And in which lecture are you? Have you already rewatched the video(s) at least one more time? I’m fairly sure that the instructor explained everything in detail.

Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

Hope this helps. :slight_smile:


See also:

1 Like

Take a look at “”_cc.Move(Velocity)" this looks like place where all the magic is happaning, for actual movement,

1 Like

The PlayerInput script checks for player input and sets HorizontalInput and VerticalInput based on input from the player.

The Character script takes that input and calculates a velocity based on it. It then passes it to the CharacterController (which is a built-in component that helps with, uhm, character control) using the Move method. The character controller does the rest

1 Like

Privacy & Terms