Game Development Reference
In-Depth Information
We also set the iling for the X-axis to 0.5 because our image contains two frames, but we
want to use only one image at a ime. We used the
Box Collider
instead of
Mesh Collider
.
We were also adding a
RigidBody
for our character and seing it to enable
Freeze Rotation
,
which will ignore all the rotaion on our character that will be calculated by Physics Engine in
Unity. This will cause our
Player
not to rotate.
The
RigidBody
will also give our character the ability to acivate the Physics Engine in Unity,
such as gravity or velocity, and act as real-life physics. We will see this in the next step.
Classified Intel
Why do we need to freeze the rotaion and posiion of the
Rigidbody
in our character?
We freeze the rotaion of the
Rigidbody
because we are using the
sprite texture to present the character movement. So, we don't want
our character to rotate when it moves. We also freeze the posiion on
the Z-axis because our character will only move on the X and Y axes. In
this way, we can also save the CPU cycles because Unity will ignore the
unnecessary calculaion and only calculate the one it needs.
Box Collider and Mesh Collider
So why are we using
Box Collider
instead of
Mesh Collider
? Both the colliders are basically
similar. Think about it this way: each surface of the mesh will have its own normal that will
be perpendicular to each verices and check if it hits any object. So, if we think about our
plane object, we will see that it has only one face that has the normal poining towards the
camera. So, it means that if we apply the
Mesh Collider
to the plane object, we won't get
any collision detecion from the top, botom, let, right, and back side of the plane. This is
basically because there is no surface at the top, botom, let, right, and back side of this
object to create the collision detecion with the other objects.