Game Advanced Prototype 2
GCC Academy
Hello
I'm Youngho Lee, and I'll be leading the lecture on creating shooting games
In this lesson
we'll cover the second part of the prototype
First, we'll understand vectors and use them
to move the player based on the uniform motion equation
Then, we'll implement movement according to user input
Understanding Vector
Let's start by understanding vectors
First, I'll create a simple sample code
We'll write code where
the player keeps moving to the right
To achieve continuous movement to the right
We'll use the following code
Transform
Translate
Vector3.right* 5* Time. deltaTime
I'll write this down
By doing this, we're implementing the idea of the player
moving continuously to the right
We put the content in Korean first
Now, if you look at this code
you'll notice it's placed in the Update function rather than Start
The reason is that the code needs to be in the Update function
when you want something to keep happening
while the game is running
After saving this
let's go ahead and test it out
When you press the play button
You can see the player continuously moving to the right
This is made possible by the line of code we just wrote is essential
To grasp this fully, we need to explore a few concepts
Let's start by looking into vectors
and then dive deeper into the code
First, what exactly is a vector?
If you look at its structure, it's represented as an arrow
This arrow has a body
I'll call here body, and this tail
I'll say "tail," and a "head"
The blue part of the arrow represents its magnitude
and the red arrowhead
indicates its direction
A vector is an element that combines
these two components
Magnitude and direction
This one which always includes both
We call it a vector
Vectors play a crucial role
when we want to express
physical movement
They're used for simple mechanics like moving objects
Also
Simulating interactions like light hitting a surface, bouncing off
and reflecting
All of these processes
rely heavily on vectors
For instance, if you look at the arrows
on the screen representing the direction of light
They're vectors
By understanding vectors thoroughly
you'll gain a solid foundation
for working with
Unity to create games
Now, let's take a closer look at the various characteristics of vectors
Vectors are typically represented as arrows
and they can undergo arithmetic operations
These operations include
addition, subtraction, multiplication, and division
Right?
However, in the context of vectors
we primarily use multiplication and division
When it comes to multiplication, there are two main types
Dot Product
It is represented with a dot and used for certain calculations
Then, Cross Product
It's used like this
Since it's a dot, we call it Dot Product
and this one with "x" symbol
So we call this Cross Product
In Korean, the dot product is called 'naejeok'
and this is called 'woejeok'
What we have to focus on is
addition and subtraction
These are really important
to do the work
And these two
are used variously
The dot product is a multiplication operation
between two vectors
that results in a single numerical value
As we mentioned earlier, vectors consist of magnitude and direction
The resulting value from a dot product
is called a scalar
A scalar
When you perform a dot product operation on two vectors
each defined by magnitude and direction
you obtain a scalar value
Next, this Cross Product, the outer product
When you do the outer product of two vectors
a vector perpendicular to these two vectors
pops out
We call this the outer product
The two vectors are used for very important roles
depending on their purpose
This time, we will learn about
addition and subtraction
Then, the important thing is how addition is used
Let's assume that there are two vectors
Let's take a look
Here is the vector of A
and then here is the vector of b
The vector of A can be placed here
and on top of this
This vector has a magnitude and a direction, right?
In other words, it does not include a location
Let’s think of vector A as wind
The wind blows continuously
It's blowing like this
It doesn’t only blow
between specific points
When you open a window, how does the wind flow?
It simply comes in
regardless of its position
When I'm there, the wind comes in like this
So, it doesn't matter where it is located
So whether you put it here or here
it blows like this
So, it doesn't matter
if I put the position of A here, this vector of A, right?
Now, let's imagine you press both the right arrow key
and the up arrow key
So what happens if the plane hits both
at the same time?
If you look at the last picture
you can see that it has to go diagonally
In other words, if you add the two vectors if you connect the endpoints like this
you get a vector
that points to the last two points
Vector addition works like this
It represents the sum of
all forces acting on an object
Let’s take an example
Imagine we throw a ball
Like this
If we throw it
will the ball
fly infinitely in one direction?fly infinitely in one direction?
Will it even go through the Earth?
For real?
No, it follows a curved path, a parabola
and eventually falls to the ground, right?
In a typical scenario, it will fall due to gravity pulling it downward
Why?
Because gravity acts
How does it work?
It acts downward
So, if you add these two arrows
It goes like this
It doesn't happen like this
Gravity gradually affects my force, so what happens?
This one goes like this
and it goes in a parabolic motion
So vectors can express the sum of all forces
when adding
If the wind blows in the opposite direction like this
And gravity is also at work
If you add them all up, how do you think the ball will fly
when the wind is very strong?
It flies like this, and then, because of the wind
it returns like this
Right? You can direct it like this
So the wind is this force
the force we threw is this force
and the gravity that falls down
When you add all these up, the object's final position is determined
I think it would be good to know that addition
is used for this purpose
Representative games include baseball, golf
and billiards
You can think of all of these as using addition to this vector
How do we use subtraction?
In the end, subtraction is also a part of addition, right?
If we have A, we can subtract it by adding its opposite
So, while subtraction is technically an addition
its purpose varies
depending on how we use it
Let's say we have vector A here and vector B here
If we subtract A
what happens?
Interestingly, subtracting A flips its direction
That's because
When negative numbers and minuses are multiplied
What happens when -1 is multiplied?
That is, the direction of the vector can be changed
Right?
Now, if vector A points this way
and vector B points this way
how do we find
the resultant vector, like in addition?
The final vector would look like this
B - A, how does it come out?
It comes out like this
How do you know this then?
It's like A wants to move to B
So, you can see vector subtraction like this
How is it used?
Imagine you are here, and your target is over there
You want to go toward the target
I want to go in the direction of the target like this
So, our goal is to find this vector
How do I do this? Where do I want to go?
I want to go in the direction of the target
Let's call this vector the direction
So how do I find this Direction, this vector?
It's Target - Me
I find it like this when I want to
go to the target
Target - Me means
I can see the vector from me
to the target, the destination
Okay? This is how I can find it
Let's find out one more thing here
Let me draw this on a graph
Let's put it
like this in rectangular coordinates
Here's the X-axis, right? Here's the Y-axis
It's like this
Let's move it over here so that it's easier to see
Then, if you look at it
I'm here, and the target is at this point
How about looking at the two positions like this?
From here to this point
let's call it x1
Here's x, here's x1
Then, at this point
let's call this Y1
In other words, let's say this vector is added
If my position is at this point
and if I add this vector to my position
where am I ultimately?
I'm at the target position
Then, if I'm standing here
and this standing character moves to that side
if I add this vector
it'll move like teleportation, right?
This isn't the type of movement we want
What do we want to do?
I want to go like this at my speed
In that direction
Then, I told you that this vector
comprises magnitude and direction
Then I don't need this magnitude
I just simply need this direction
and I'm just going to move this character
in this direction
Then
I said that it comprises magnitude and direction
I wrote multiplication here
At that time, I only needed direction
So I'm going to have my movement speed
I'm going to multiply my speed here
Then the vector's magnitude
doesn't simply becomes something
But I want it to be like this
So I want it to move this much at my speed
Then, what if this vector we got by subtracting vectors
becomes specific speed, it's my speed
This is me
Will only my speed and direction remain?
What should this magnitude become?
It should be 1
So this action of making the magnitude of this vector
this direction
from Target - Me 1
is called vector normalization
In English, it's called Normalize
That's what it means
This is the action I take when I want to move at my speed
with this vector
that I got by subtracting vectors
At this time, vector normalization is used
Then you guys will make a game
Let's say it's an MMORPG game
I clicked here with the mouse pointer
I clicked here like this
Then, the character should stand here
and move in this direction
Then how do I do it?
My position, the position of the target that the mouse clicked, will be found
If I do Target - Me, this vector will be found
Then I will move in this direction
In something like an MMORPG
Then, instead of just adding this vector
you have to normalize it
to make it fit into this vector
In other words, if you make it into a normalized vector like this
you can move in that direction
at your speed
This is called normalization
So vectors are largely
divided into addition, subtraction, inner product, and outer product
but this time, we only looked at addition
and subtraction
Then, in this sentence we mentioned earlier
in the part where the player goes to the right
there's a part that says Right here
This is a vector
so it has the direction of the right side of the vector
What is its size? It's 1
What's the 5 at the end?
That would be my movement speed
The one behind, I'll talk about it again later
is just the time used in uniform motion
The time used in uniform motion
So what?
That's the vector I created
And the one behind is the time multiplied
Understanding Constant Velocity Motion Formula and Player Movement Creation
Then, let's learn about the formulas
for uniform motion
If you look
it's about Newton's kinematics
The first part is P = P0 + vt
v = v0 + at
The third is F = ma
It goes like this
The last one is F = ma
It's probably ingrained in your DNA
What about F?
I don't know where you use it, but ma?
The part that comes out like this is where it says F = ma
So when an object moves dynamically
or becomes like this by kinematics
These three formulas are used
That's why the physics engine embedded in Unity
also uses these formulas
to implement the parts where objects move
The first of these is the formula for uniform motion
Let's say there's a person here
You guys push them from behind
You push them with a bang
What happens to this person then?
If you push them from behind
they'll get pushed this way
Of course
At this time, the shape in which the object moves
is created by this formula
First, let's put P0 as the current position
of this person
This is the current position
Position
Next, this is my future position
Let's put P
Next, there's
the direction that occurred when the user pushed from behind
This is an arrow
What do we call this?
It's called a vector
Let's put V, which stands for velocity
Velocity, V
This is a vector
So, this person doesn't move instantly
but moves gradually over time
That's why there's a T at the end
So they move over time
Let's take a look at this again
I pushed from behind
Did you?
When you push this, a force is applied
A force is applied
The one in front is called uniform motion
The one behind is called uniformly accelerated motion
The last one below
the force goes up to F = ma
This also goes like this
Now, what is A here?
This part affects the current position
which is velocity
Velocity
a is acceleration that affects velocity
Okay?
Here, m is mass
The mass of the object
So, let's put mass as 1 here
Then what will F be?
It will be a, right?
I pushed from behind with force
What happens then?
a is created
Where does a affect?
It is added to the current velocity
so v0 is also the current velocity
v0 affects the current velocity, creating a new velocity
A new velocity is created
and v has changed
This part has been created
So where does v affect?
It adds to the current position
and changes the future position
So when you push from behind like this, force is generated
Force means acceleration is created
Then, by affecting this part, a new v is created
Then, the structure that creates this structure
where the player P0 moves to P
can be seen as the formula for uniform motion
Then, what are all the games
or realistic content
that we create?
They happen in virtual space
We simulate in virtual space
To do that
we have no choice but to understand the dynamics part of kinematics
Games are ultimately about creating dynamics
that are identical to reality, similar to it
So we have to use this kinematics
in our games
The important thing here is
the vector
Then, if we look at the content a little more
P0 that you see here
is just the simple position of a certain player
Position
P is also just a position
Here, t is a scalar value, time
Here, v means this arrow
So we draw a vector
on the head like this, an arrow like this
What is this?
It's an arrow, a symbol for a vector
a is also acceleration, gravitational acceleration
The arrow is acting downward
So, this is also an arrow
F is also an arrow, a is also an arrow
The m here is mass, so it's just the number 1
A scalar value
We can express it like this
This is the formula for uniform motion
We'll use this to create
our player's movement
Let's use this
to create our player's movement
If you look at the code
this part itself
this much in this part
is v
Why? What is P?
P0 + vt
This is a vector
and v is a vector with magnitude and direction
So V is created by multiplying direction × magnitude
The t behind here is called deltaTime
This transform.Translate
This internally implements this formula
which is the internal function of this translate
So this deltaTime behind here
means t
So, let's take a quick look at
what this deltaTime is
Let's take a closer look at deltaTime
If you look at the one in front
and below
this is a new PC
I opened up a new computer and bought it
I bought it with the latest graphics specifications
memory, hard disk
and everything
The one below is
a PC that's about 5 years old
It wasn't bad then
but it became very slow after about 5 years
You see this dotted line on the graph above
This graph shows
how often a new PC can perform operations
in 1 second
So let's say this is 1 second
How can a new PC perform in 1 second?
When this object moves
it can move one, two, three, or four times in total
It can perform four spaces in 1 second
And two times under
Do you understand?
You can do this two times
and let's say this character can move
1 meter each time it moves
Then the new PC above
moves four times
so it moves 1m each time
So how many meters can it move in 1 second
on the first new PC?
4 meters, right?
Then, the 5-year-old PC below
can move twice
Likewise, it can move 1 meter
each time it moves
Then it will move 2 meters in 1 second
How about this?
Since it's a new PC, it can move 4 meters in 1 second
and this one can move 2 meters
The PC above it can move fast
when you play
the game
In other words, if a 5-year-old PC and a new PC play a game
the first new PC will always win
This is so unfair that
users will stop playing the game
Do you hear the sound of the low-priced users leaving?
This is so unfair that
the rules are so unfair
So how can we make them arrive
at the same location 1 second later?
This is a very important point
Then, instead of 4m or 2m
how can we make them move at the same speed 1 second later
and arrive at the same final destination?
This is the core of deltaTime
There is something called Delta in front of this
This Delta is displacement and change
This is displacement time
What has changed? Time has changed
How has it changed?
Right here
how long did it take from the first
to the end of this frame?
This is deltaTime
If the whole thing is 1 second
when you do it 4 times
each frame, each space
we call it a frame
Did you play this game when you were young?
There's a book like this
If you have a book, you draw a picture here
How about on the back?
You draw a picture like this on the back
A running picture
and then we'll draw this on every page of the book
and quickly flip through the book
What if we flip through it quickly?
We can create an animation
that looks like it's running
You've probably played this game before
There's each of these
What do we call each of these?
It's a frame
In some places, it's called a tick
In Unity, each of these is called a frame
Usually, in the animation or film industry
for us to see these smoothly
how many frames are created per second?
These ones
These are produced at about 24 frames per second
That's why we call this frame rate per second
or frames per second, fps
This is not first-person shooting
That's right, frame per second means
24 frames are created per second
These are usually in the animation field
When you watch a movie in the theater, animated movies
usually use about 24 frames
Then, games
usually use about 30 to 60 frames
Content such as VR
is available in at least 60 frames on mobile
PCs use 90 frames or more
Why? So that users don't feel dizzy
when they turn their heads or eyes
This frame rate per second
fps is used
Now, this deltaTime plays a very important role
How short it takes
will help determine the frame rate per second
So, here's how deltaTime is used
in the uniform motion formula
If you look, this can move 1m
However, the time taken for each section is 0.25 seconds
so if you divide it by 1/4, it becomes 0.25 seconds
So when we move, the distance
is space S, just let's call it S
Then, in terms of distance and time, let's call it deltaTime
× D
That's when we get this final location
So, we have S × distance × time
Let's see, when we do distance × time t, these two things?
It moves 1m
Let's multiply time by deltaTime
What do we get? 0.25 seconds
What is the value?
The final distance traveled is 0.25 meters
So, how many meters did it move when moving this section?
0.25 meters
After this, 0.25 m, 0.25 m, 0.25 m
If we add them all up, the final distance it moved is 1 meter
The same goes for the bottom, even though it's slow fit
But it takes 0.5 seconds per section in deltaTime
In this case, it took 0.5 seconds to move 1 meter
If we multiply the two, how many meters did it move when moving this section?
0.5 meters
If we add the two, how many meters did it move? 1 meter
So before, this one was 4 meters, and this one was 2 meters
but now the two are the same
So, deltaTime is used like this
So, in the uniform motion formula
P = P0 + vt
but P = P0 + vt, the t at the end
is the time of the movement
Because of that time, we multiplied by deltaTime in the code
but for synchronization processing
you must multiply deltaTime
This isn't just used for simple movement, right?
Let's take a look at the form that you rotated
Here's one character
and here's two of them
They're both looking this way
Let's say there's a hammer here
There's a hammer like this
When they both say Start!, they'll spin around
They'll spin around and hit this guy with the hammer
This is the new PC, this is the old PC
This guy can spin faster, right?
Boom! What if he spins around, catches the hammer, and hits him?
The new PC will win, right?
That's why you have to multiply by
deltaTime when processing the spin
Okay, let's look at this case this time
I'll put a pill here like this
I'll put it like this
When you say Start!, you can each take this pill
you can each take it when you say Start!
When you say Start!, this guy can take it, and this guy can take it
At that time, this guy is the pill that expands
This is the new PC, and this is the old PC
This one will eat this and zoom in, how about that?
It zooms in fast, right?
4 times per second, and this one can zoom in twice
so this one will zoom in four times
So what does this one do? Boom
So after it gets this big, I stomp on it and bang!
This one's definitely going to win the game
That is, when you rotate, what do you have to multiply by?
You have to multiply by deltaTime
When you try to change
the position, rotation, and scale
used in this transform component
you have to multiply by deltaTime
to synchronize them
That's how we found out about deltaTime
Next, let's change
this transform.Translate
to the uniform motion formula
we just learned
Instead of using the one provided by Unity
let's implement dynamics by directly working on physics
using the uniform motion formula
What is the movement formula?
It's P = P0 + vt
So what we need first is P0
P0 will be the current position of the player
So, let's create P0 first
Vector3, this is the data type in front
It allows you to use the three elements
provided by Unity: x, y, and z
That's why it has the 3 at the end
In 2D, it's Vector2
When there's only one number? Just use float
Since we're in 3D, let's put it like this: Vector3
Let's put it as P0
This is the current position of the player
so there's a game object
that PlayerMove is using
Who has this player's position?
Transform has it
If we get this position value
we can get its current position value
How do we use it? Here's how you can write it
transform.position
If you write it like this, P0 is created right away
This is putting my current position into P0
Next, we need vt, right?
So if we do vt to Vector3
what happens to v? This much will be v
This much is v
The thing after this is direction, and this is magnitude
so this much in magnitude × direction is v
Next, t is deltaTime
So if we multiply this by the end, this becomes vt
Then, let's create the last P = P0 + vt
P = P0 + vt
It will be like this, then it will finally be created according to this formula
Since we got the value like this
it should be updated to my final current position
So transform.position
What do I put
in my current position? If I put P
​​this value will be updated
This part is no longer needed so that you can delete it
We create this using the uniform motion formula
that changes the current player's position
Let's see if it has changed the same
If you press the play button, the user will continue to move to the right
It looks like this
Implementing Movement Based on User Input
Then, this time, let's implement movement
based on user input
User input creates this that can get
the direction based on the user's input
It allows you to get the user's direction
What is the direction here?
This part will be the user's direction
In particular, since this is the size
this part can be limited to the direction
Here, the parts that we need to learn a little more about
Vector3.right are
that this Vector3 part
creates a direction
with three components: x, y, and z
In Unity, x means right
y means up, and z means directly in front
In English
this x direction can be called right
this can be called up
and this can be called forward
When it becomes like this
How does each value go into x, y, and z?
Vector3.right needs to enter the values ​​of these three components
In other words, since x is right, the value goes into this as 1
y goes into 0, and z also goes into 0
Since it will go to the right if there is no value
Its size is 1
Here's how to find the magnitude
You can find it like this, √(x^2 + y^2 + z^2)
Since this is 1, the remainder is 0, and the square root of 1 is 1
So, the magnitude becomes 1
It becomes like this
Then, in addition to the right, there will also be up
What will up be like?
In this form, you only need to enter a value for the y-axis
That is, x is 0, and y is 1
When is it going forward?
It'll be 0 for y and 1 for z
What do you multiply when the direction changes?
I said that if you multiply by -1, the vector will flip
So if you say you're going backward
If you want to go backwards in a vector, this is in front
You can multiply by -1
On the left, multiply x by -1
That means multiply by × -1
Since each component is multiplied like this
0 × -1 is 0
So, you can also do this to go down
So, if you × -1, the vector is flipped
You just need to know this
Then, let's implement the content
that receives user input and makes the player
move up, down, left, and right
Then, let's first get the user's input
to create a direction here
We want to create a direction by getting the user's input
Then, how do we get the user's input?
We use a class called Input to get the user's input
Then, picture class 1 in your head
Then, what happens?
We go into the function as an attribute
We'll go into the function here
We'll go into the GetAxis function
GetAxis can get the inputs
that the user is continuously pressing
Here, we'll get the Horizontal input
which is the left and right input
If the user doesn't press any key
GetAxis returns a value of 0
However, if the user presses the A key or the left arrow key
it returns a value of -1
It gradually changes from 0 to -0.1, -0.2
and returns a value up to -1
If the right key is pressed, it returns a value of +1
We'll use this
to create the direction of this vector
We'll store this as a value for the Horizontal input
for the left and right input, which is a container called float h
So, where is this Horizontal value?
If you go to Unity and scroll down to the Edit menu
you will find Project Settings
If you go in there, you'll see Input Manager
There's a section called Axes in the Input Manager
If you open that, you'll see Horizontal
If you look under that, you'll see Vertical, Fire1
that Unity has mapped
inputs to in advance
If you open Horizontal, the name is Horizontal
and here it says Negative Button, left
Next, Positive Button is right
That means the left and right arrow keys
It means negative and positive numbers
the Alt key and other alternative Negative buttons
are the a and d keys
So when you press the left, right, a, and d keys
Horizontal responds
This value passes a value between -1 and 1
It's defined here
It's defined like this
Vertical is up, down
and s, w
What's in fire1?
Left ctrl key or left mouse button
0 is the left mouse button
The values ​​are defined like this
We put the values ​​defined here
and work with them
We will process the values ​​using these values
Then, let's first change
the direction to the value we put here instead of this
So we're going to put dir in Vector3
This is right
It's the right value
If we do this, this dir has right in it
and if we just do this instead of right, what happens?
It moves to the right, and the same value will appear
At that time, if we want to
apply the user's input value to this
we multiply it by the scalar value h
Then what happens internally?
Right is 1, 0, 0
and if h is -1 here
if we press the left key and do this
each component will be multiplied like this
Then what happens?
It will be -1, 0, 0, so it will be the left
If we press the right, it will be +1, so it will just be 1, 0, 0
and it will go to the right
If we don't press anything, this has a value of 0
So the direction will be 0, so nothing will move
0 × 5 is all 0, right?
So, if we multiply this by h here
we can immediately set the direction
Let's play this
Play
Let's press the left and right keys on the keyboard
Then you can see that the character, the player
moves left and right like this
Okay? Then how about the up and down input?
As I mentioned earlier
what was this value in the Input Manager?
It was Vertical Let's create another one
Let's call it v, and this time, put it as Vertical
You have to distinguish between upper and lower case letters
Then the user's input is like this
If I want to add one more Vertical
do I have to create another direction to move it?
You don't have to do that
You can use vector addition
How? What happens if you add
these two vectors, one going to the right and one going up?
I said you can put this here
That's how this vector is created, right?
So you can add the two vectors
+ Vector3.up * v, if you do this
when the value is -1, it will go down, and the vector
This is 0, 1, 0
so when it's +1, it will just go up
Then, if you change this formula
for moving an object
you can make it like this
It's about finding directions
Up to here, it's about finding directions
What's the content below?
It's about moving
You can use sentences like this to distinguish them
Then, moving
always ends with the word moving
If you want to change the direction or do various tasks
you can just change the code here
Even if you create a function
you can just change and create this part of the function
I've done it to move the user up, down, left, and right like this
Let's test it, play
Then, you can see that it moves when the user presses
the left, right, up, down, left, and right keys
Then, we'll continue to look at
this part in more detail
How can we see the light of a vector?
You can see the light of a vector like this
(1, 0, 0)
What happens if you multiply it by h?
(h, 0, 0)
Let's add them
The up × v of a vector can be seen like this
(0, v, 0), let's add two of them
Then, what will the final value be? (h, v, 0)
In other words, can we put each component
in x, y, and z like this?
So we can modify our code like this
If you place the part like this
in the new Vector3 as (h, v, 0)
the content will be the same
Let's save and play again
It can be implemented similarly when moving up, down, left, and right
So, we add to the vector and extract the final result
Those results can be entered into the vector like this
and the content can be the same
So, does that mean we don't need to add to the vector?
You might say that
No, adding to the vector is
necessary because it implements the sum of all forces
I'll show you that this can be used
when you reduce the user's input to a single value
The code may appear like this
when you study and search
on YouTube or Google
Ultimately, these are based on adding to a vector
I hope you understand this
Let's summarize what we learned in this section
First, we learned about vectors
Vectors consist of magnitude and direction
and can perform addition, subtraction, inner product, and outer product operations
Second, we learned about the uniform motion formula
We learned about the uniform motion formula for moving an object
P = P0 + vt
We created the player's movement
We moved the player based on the uniform motion formula
We also learned about the meaning and use of deltaTime
We implemented movement according to user input
We used the inf class to get the user's input
and applied the player's movement by calculating the up, down, left, right directions
based on the user's input
Understanding Vectors Vector Vectors have magnitude and direction Can be added, subtracted, and multiplied (inner product, outer product) The sum of all forces can be expressed by adding vectors
Direction=B-A (a formula to find the direction in which A wants to go to B)
Understanding the Uniform Motion Formula and Creating Player Movement Uniform Motion Use the formulas for movement, velocity, and force as the physical laws for moving objects P=P0+vt / v=v0+at / F=ma
DeltaTime The time between the previous frame and the current frame It is important to match the distance traveled per second regardless of the PC specifications
Implementing movement based on user input User input processing Write code to respond to the input of the left and right keys, A, and D keys on the keyboard
Write code to respond to the input of up, down, left, and right using Horizontal and Vertical registered in the properties of [Edit - Project Settings - Input Manager]
Creating a direction Implementing the content of 'Creating a direction and moving according to user input'
Using the value received from user input to create a direction (Vector3 dir=Vector3.right*h+Vector3.up*v)
Using (h, 0, 0)+(0, v, 0)=(h, v, 0), change the script to new Vector3(h, v, 0)