Light, easy and fast Field of View 2D

September 11 | 14

So I was working on a personal project that requires some AI to have a field of view to check if the player has been seen or not by the AI.

I searched on the asset store and to my surprise there is nothing like this implemented nor in the internet, so I decided to quickly implement a fast, light and small version of a small field of view for 2D.

My implementation doesn’t use physics at all, without further ado, here’s a quick explanation of the component; to use it just drop it on a GameObject and it will run automagically.

Inspector vars
Radius: Radius of the field of view, how far it can “see”.
FOV (Field of view): Angle in degrees how wide the field of view will be, by default 90 degrees
Direction: Defines the direction where the field of view will be pointing at, this vector internally gets normalized.
Test Point: This is a transform reference to test the field of view when hitting play.

And this is how the field of view will be seen in the scene view; the green line shows the direction and the yellow lines determine the FOV edges.

FOV Scene view


Finally the source code can be found here, feel free to use it in your commercial projects and also include it in your Asset store packages if needed, still you don’t have permission to sell this script alone in the Asset store.


Lets talk about draw calls.

September 2 | 14

I’ve been thinking on making a post about draw calls but havent had the time / will to do it, so lets just get over with and start :).

Lets first define what is a draw call.
A draw call is a command to the graphics card that tells the GPU to render a certain set of vertices as triangles with a certain state (shaders, blend states, etc).

Now a frame is built of draw calls, that means the lesser draw calls you have the faster a frame finishes rendering; hence higher frames per second.

So just check this video to understand better how a single frame gets rendered in the C4 engine:

So, after watching this your might ask: how can we reduce the number of draw calls in our project?.
Well its fairly easy, try to compress as many objects/parts of a model into the less number of textures as possible.

This means that if you have lets say 5 objects with 5 materials that use a metal shader, just remap the UVs of the objects to a single texture, pack the textures into a single texture and use just 1 material for the 5 objects.

Something like this:


By doing this in Unity you can reduce up to a third the number of draw calls that you currently have in your project without losing any quality on your work.


Its important to keep draw calls as minimum as possible, this is because you can render your frames faster and also can use some rendering time in other tasks like AI.

If you are in need to reduce the number of draw calls in your project and you don’t have the time / knowledge to re-map all the UVs of your meshes you can use this tool I wrote for free to reduce your draw calls in Unity from here.

Finally if you are still interested and want to get more deep on this topic, you should checkout the nVidia presentation Batch Batch Batch!, a bit old but covers the draw call performance topic.

Space Invaders in SMFL and C++

March 13 | 14

I was planning to write this over the last year but never happened, now that I have some free time I’ve put this post together and here it goes.

I like to work on stuff different from Unity from time to time, and I was feeling rusty on my C++ skills so I needed a small project which I could finish over a week on my free time to study some C++. After thinking what to do I decided I wanted to do a game but wanted to use something different from SDL because I already have worked with it before so after googling on different frameworks I found SMFL (which I loved it for its easiness) and decided to give it a try.

The game I ended up doing was a space invaders clone. This is an OSX project developed in XCode. but it should be easy to port it to windows and linux. it should be a matter of just setting up the IDE and SMFL in your platform.

I also published the code I made with an MIT License, so you can do whatever you want with it. If you want to check/use the code, feel free to fork it from here

Here’s how it looks:

Dungeon Lords – Work In Progress

February 9 | 14

So I’ve been working for the past year on a dungeon keeper clone (its one of my fav games) and basically after lots of trying with the tiles I decided it was best to generate them in order to make them be as organic as possible and to match each tile with the other.

Here you can see a small video where I have the minions (red cubes) digging on the tiles the player commands to dig and after finishing digging they start to populate (as in conquer) the places that are unclaimed with the player’s tag.

Any Comments / Suggestions / Questions? feel free to write a comment


ProMouse – Control your mouse position from Unity.

July 9 | 13

Continuing with my small utility scripts for Unity, I’m releasing ProMouse for Unity, its a set of libraries that lets you control the mouse position within Unity, as Input.mousePosition in the docs is read only. This package works seamlessly across Windows, OSX and linux operating systems.

In order to modify the mouse position I  exposed a simple and small API to move your mouse locally or globally in the Screen.

NOTE: All the global coordinates for this package are relative to the main screen.

For more detailed info on how to use this package, you can also check:

If you are still interested you can also get the package at:


The only class you should access when using this package is the ProMouse


The ProMouse.cs class is a singleton that you can call from anywhere in your
code and exposes the following functions:


// Sets the cursor position to (xPos, yPos) pixel coordinates relative to
// Unity's window.
// The bottom-left of the window/screen(in full screen mode)
// is at (0, 0). the top-right of the window/screen(in full screen mode)
// is at (Screen.width, Screen.height)
public void SetCursorPosition(int xPos, int yPos);

// Sets the cursor position to (xPos, yPos) pixel coordinates relative to
// the main display
// The bottom-left of the main display is at (0, 0) and the top-right of the main display
// is at (ProMouse.Instance.GetMainScreenSize().x, ProMouse.Instance.GetMainScreenSize().y)
// which is your current main display resolution.
public void SetGlobalCursorPosition(int xPos, int yPos);

// Returns the value of the global mouse position relative to the main
// display going from 0,0 on the bottom-left corner of your main display to
// (ProMouse.Instance.GetMainScreenSize().x, ProMouse.Instance.GetMainScreenSize().y)
// on the top-right corner of your main display.
public Vector2 GetGlobalMousePosition();

// Returns the value fo the local mouse position relative to Unity's
// window, this is the same as Input.mousePosition
public Vector2 GetLocalMousePosition();

// returns your main screen resolution, this is the same as calling
// (Screen.currentResolution.width, Screen.currentResolution.height)
public Vector2 GetMainScreenSize();


Example usage. 

In order to access any function of the ProMouse class you just need to type

“ProMouse.Instance.” + the name of the function you want to call.

In example for setting the mouse position at 0,0:

void Start() {

For checking all the functions of the ProMouse class working just refer to
the Example.cs class that comes with the project.


For Advanced users:

ProCursor.cs is a singleton class that creates a hidden GameObject to act as a way
to call a coroutine for moving our mouse as we need to wait one frame in
order to get the updated mouse position.

This coroutine is needed in order to update the mouse position and get the
correct values but you dont need to worry about that, you just need to call:

ProMouse.Instance.SetCursorPosition(pixels on x, pixels on y) or
ProMouse.Instance.SetGlobalCursorPosition(Pixels on x, pixels on y)

Depending on your needs.

In case you need to do an operation between when the mouse gets updated to
the new position after moving the mouse (which only takes one frame), there
is a flag that lets you know if there is an operation being performed on the
mouse and can be accesed like this:

(bool) ProMouse.Instance.MouseBusy; (read-only)

*** *** *** *** *** *** *** ***

The ProMouse package will work straight on any platform natively, but if you are
testing your projects in a virtual machine the mouse position gets internally
updated but you will not see your cursor moved; This is caused because the
virtual machine installs mouse drivers in order to seamlessly go from the
Host OS to the virtualized OS.

So basically what you need to do is to disable the mouse integration with the
virtual machine.

Here are some links you can check regarding vmware but they are not
assured to work: (VMware specific)

Maybe this will work on other virtual machines maybe not, if it
happens to work out of the box in other virtualizing software just share it
in the comments so people can know where it works.