Snap vector direction to nearest axis

I have this case when I need to get my character direction is snapped to the nearest axis. Kinda look like this.

My solution is to find the largest axis absolute value of axis. Then, change the largest one to 1 and the others 2 with 0. Change largest axis sign with its original sign.

Example, we have Vector3(-0.5f, 0.1f, 0). The snapped direction is Vector3(-1,0,0).

Vector3 SnappedToNearestAxis(Vector3 direction){
    float x = Abs(direction.x);
    float y = Abs(direction.y);
    float z = Abs(direction.z);
    if (x > y && x > z){
        return Vector3(Sign(direction.x),0,0);
    } else if (y > x && y > z){
        return Vector3(0,Sign(direction.y),0);
    } else {
        return Vector3(0,0,Sign(direction.z));

How to get reflection vector?

Reflection Vector

This is one of the problems I encounter often. It might be useful to put solution here.
If you are in hurry or don’t need any explanation, I’ll just leave solution below.

v2 = v1 – 2(v1.n)n

v1.n is dot product & n must be normalized.

Vector3 ReflectVector(Vector3 inputVector, Vector3 normal) {
    float dn = 2 * inputVector.DotProduct(normal);
    return inputVector - normal * dn;
Continue reading How to get reflection vector?

Productivity tips : Don’t place your distracting apps on front screen!

In this era of internet addiction, checking phone regularly is unsurprisingly common and it messes up your productivity.  One of the solutions is to make it difficult to reach these apps (Instagram, Twitter, FB, etc).

In order to do this, you must place these apps away from the front screen, put them in one folder named “Useless apps”. It doesn’t always work, but at least extra efforts to reach these apps will give you time to reconsider your decision.

Fill your front screen with “good” apps like your fitness/workout apps, todo list, or any productivity apps.

I got this idea from Reddit. Hope it helps.

Bolderline, a colorful brick matching puzzle game that will challenge your brain.

Finally, I’ve released Bolderline. Better late than never.

Quick description, Bolderline is game mix between Tetris & Twofold Inc. One redditor told me, “It’s like Rubik’s cube and Tetris had a child.”

Here’s what gameplay looks like.

You can download it free on play store


Update after 9 months

It’s been 9 months since the last post. Almost forgot, I have this blog. haha. Development of my game still continue. It’s just slow progress. I can’t focus on this game after doing many other projects. So, at the beginning of this year, I decided to focus and finish this game.

Here are some changes after 9 months.

  • Switched game engine from UE4 to Urho3D. My game is too casual for UE4
  • New design. I got help from my friend to design the look of my game. We use minimalist style.
  • Game run & tested in windows, html5 (webgl), & android.

September 2017

January 2018


More updates will follow. I hope I can finish this game in February.