2015/03/29

Unity notes #1: Rigidbody VS Collider

While I am going through the tutorial roll a ball, I found that Rigibody and Collider confuse me a lot. I have to do a bit searching so that I can tell the differences between them.
To be honest, official document states the differences clearly. What I am writing below is a kind of rewording so that I know what is going on.

Definition from unity document

Rigibody enables your game object to act under control of the physics.
Collider defines the shape of an object for the purposes of physical collisions.

Similarity between Rigidbody and Collider

  • They are both components that can attach to game objects.
  • They both belong to the physics system in Unity.

Differences

Rigidbody

  • Usually, there is one rigidbody for a game object
  • Where physics take effect (Force, torque)
  • Variation of Rigidbody: isKinematic

Colliders

  • It is common for a game object to have more than one collider to form a compound collider
  • Where collision take effect (2 colliders crashes. Note that at least one Rigidbody must be attached to one of them)
  • Variation of Collider: isTrigger

Pitfalls

Game object falls through the floor plane

Reason
  1. IsTrigger, property of a collider, has been switched on for that game object. No collision occurs between that game object and the floor. Or
  2. There is no colliders attached.
Solution
For 1,
  1. Turn off IsTrigger or
  2. Turn off Use gravity for the rigidbody or
  3. Turn on Is kinematic for the rigidbody
For 2,
  1. Attach a collider

Move static colliders

Reason
A static collider means there is at least one collider attached and NO any Rigidbody attached. Unity assumes this kind of colliders won’t move so that they can make optimisations.
If you moving them during game play, it degrades your game performance a lot.
Solution
  1. Do not move those colliders. Or
  2. Attach a kinematic Rigidbody to that game object

Puzzles

  • For colliders, turn on IsTrigger or not?
In term of behaviours, other objects cannot pass through colliders without turning on IsTrigger. Therefore, whether or not turning on IsTrigger depends on your situations.
  • For Rigidbody, turn on IsKinematic or not?
(Rigidbody + kinematic + Collider + trigger) behaves similar to a static collider. However, moving this kind of game objects won’t degrade our game performance as the static does.

2015/03/13

How to use git to do development #0

Preface

As git becomes popular, more and more developers are trying to make use of it in order to manage their project’s revisions.

However, they may not know where to start and how to do better.

For sharing and showing benefits of using git on development, I am going to write several blogs for documenting how and why some approaches are better to follow.

Hopes you will enjoy this series.

Feel free to point out mistakes I have made :).

Learning resources

Newbie

An online tutorial which go through typical usages of git.

Advanced

An open source book explains git, including introduction, workflows and demonstrations. I strongly recommend you to go through this book if you would like to master Git.

If above links cannot help you, checkout this one which provided by github.

What’s next

To be honest, this blog just suggest you links so that you know where to start and get help.
In next blog, I will show you my git configurations and explain why I wrote like that.

Ways to navigate directories in Linux

Generally speaking, there are 2 types of commands for navigating directories in Linux system.
They are listed in the following.
  • cd
  • pushd and popd

cd

$> cd <PATH>
Besides jumping to <PATH>, command cd will also remember the last directory you have visited. It means that you can jump back and forth between the current location and the previous location.
# For demonstration, assuming we are staying at dir1 first
$ ~/dir1>

# Go to dir2 
$ ~/dir1> cd ../dir2

$ ~/dir2> 

# Jump back to dir1
$ ~/dir2> cd -

$ ~/dir1>

# Jump back to dir2
$ ~/dir1> cd -

$ ~/dir2>  

pushd and popd

Since command cd is able to remember only one directory, you need to use pushd and popd if you would records more.
# Assume we are staying at dir1
$ ~/dir1>

# Go to directory dir2 and records down
# NOTE:
# There are 2 records. The left one represents current directory while the right 
# one represents the directory you have pushed.
$ ~/dir1> pushd ../dir2
~/dir2 ~/dir1

$ ~/dir2>

# Go to directory dir3 and records down
$ ~/dir2> pushd ../dir3
~/dir3 ~/dir2 ~/dir1

$ ~/dir3>

# Checkout current directory stack
$ ~/dir3> dirs
~/dir3 ~/dir2 ~/dir1

# Go back dir2
$ ~/dir3> popd

$ ~/dir2>

# Go back dir1
$ ~/dir2> popd

$ ~/dir1>

# Errors
$ ~/dir1> popd
bash: popd: directory stack empty