Monster shadow

VIDEO

How to make a moving character in Unity

Description:
Learn the basics of moving objects in Unity as well as a few different approaches to fit your game needs. First, you'll learn how to directly change the transform position of your object. Then I'll show you how to move your character using Unity's physics engine so you can correctly collide with other objects. ========= PlayerController.cs: https://pastebin.com/muc8pBRr
ADD A COMMENT

Tarodev
I've just created a Discord channel. Come drop in for a chat 😊 it's early days and I'm sure it will undergo many changes, but let's gooooo! https://discord.gg/GqeHHnhHpz
srisrid multi purpose channel
:)
srisrid multi purpose channel
I will get on my laptop then I will join
Vskutku Trigen
we change velocity, Should not that be in Fixed update ? And also we dont need delta time when changing velocity ?
Tarodev
Nope, setting velocity directly does not require Fixed Update. We don't need delta time as we're setting the value to a specific number and not ADDING a value to the current number. Hope that makes sense!
Baris Dincer
I just discovered your channel and videos. Good job there! One question about this video though. Wouldn't it be better if you used FixedUpdate method instead of Update, when you're dealing with physics?
Tarodev
As a rule, you're right and it's generally better. For example if we were adding force it's better to place it in FixedUpdate (although that's what multiplying by Time.DeltaTime allocates for). For this scenario where we are setting the velocity directly there shouldn't be a difference either way. But generally, yes.
Sarthak __Rgv
hey could you tell me how can i make a cube roll on a grid such that a cube of length width and height of 1 unit would roll onto a grid of 1 unit length and width(like a chess board) and be perfectly centered on the next adjacent grid tile it has been rolled to. Hope i'm clear?
Tarodev
Here, I just made a video about it: https://youtu.be/V9rVZ9mf0uA
DevsGamer
Nice! Could you make a tutorial about how to set the camera and post-processing that you used for this tutorial. Thanks!! :)
X-Tech Gaming
i just came across your channel and seems u have amazing detailed stuff. I wanted to know how to make a game manager, but I wish if u do a detailed longer video on how to make all of managers scripts/event and and when and how to use them
Pulkit Dubey
also please make a video about character controller
Pulkit Dubey
love you i wasn't able to understand a thing before and i was going to quit unity thanks to u !!
Tarodev
Awesome. Glad you didn't quit unity 😊
Sir Plum
thanks ill try this out later
DurVids
Great stuff! Very concise and to the point and super well explained. Looking forward to more content!
Lora
Hello, you don't know how to do this: https://youtu.be/vmaB9v15X18
Raoul Best
Amazing video! The quality is the thing that makes it shine, especially that great atmosphere and not a blank unity scene. Hopefully people who need will find this channel.
Tarodev
Thanks Raoul! I like to try provide a feast for your eyes as well as your brain 😊
GAME KING
Very good, good luck, man 👍👍👍
VanillaHoward
Amazing video!
srisrid multi purpose channel
Good and also excited for discord server
srisrid multi purpose channel
@Tarodev i am joining
Tarodev
Check the pinned comment 😊
Duda_Andu
Waiting for that discord server man
Tarodev
Alarm triggered! Check the pinned comment
Tarodev
I just set an alarm for tomorrow to do it. Thanks for reminding me!
SEE ALL COMMENTS


Transcript:

stick around and i'll show you a few ways to get your character or an object
moving around in your game let's get stuck into it
to start create a new c-sharp script and call it
player controller now attach it directly to your player
object to show you the basics let's use this
code inside your update function create an if statement checking if the
player presses w on the keyboard if so move the player one unit forward
vector3 forward is shorthand for new vector3001
now in the editor press play and then w on your keyboard
your character should move one world unit on the z-axis
but this is a bit boring so let's continue
let's alter the code first add a serialized float called speed so that we
can adjust it in the editor next we need to gather player input to
determine which direction to move we create a new vector3 called der and
we set x to input.getaccess horizontal
0 for y and input.getaxis vertical for z this uses the built-in unity input
manager ensure you spell these exactly right or
they won't work as expected next we reference our object transform
and use the built-in function translate fade in the direction we just gathered
multiply it by our spade variable and then to ensure we have a balanced
experience across multiple devices and frame rates
multiply it once more by time dot delta time
press play in the editor and use the wasd keys or the arrow keys to move your
character around you'll notice it's very slow let's pump
the speed up a bit using the speed float we exposed in the script
awesome a downside to using translate is that it directly manipulates the
transform position of the object which means you will push right through
other colliders this may or may not be a problem for your game
but keep watching and i'll show you how to move around using unity's physics
engine so that we can collide with objects as
we'd expect add a reference to the player's rigid
body we'll collect the direction the same as before
but instead of using translator to set the position directly we'll instead set
the rigid body's velocity in the editor add a rigid body to your
player object freeze the rotation on all axis and set
interpolate to interpolate to provide a smoother experience
also ensure you have a collider attached as you can see
the plane now collides properly as well as starting and stopping
with a bit more realism if you really want to make this a party let's add a
rudimentary jump to our character first add a new serialized float called
jump force we need to change the way we gather
player directional input to ensure we're not messing with our jump velocity
grab our input and multiply it by our speed variable
next let's set our y velocity to whatever it's currently sitting at
which will change when we jump set our rigidbody's velocity to this new value
to get jump working check if the user presses space flow and if so
add force to the rigid body fit in up as the direction
and multiply it by our jump force press play
and smash the space bar to make your player jump
heck yeah before you leave subscribe to my channel for more tasty tutorials
and good luck with your game development journey