Posts Tagged ‘Game Programming’
These posts are related to game programming.
Unity: Raycast Reflection
Posted by Dimitri | Filed under Featured, Programming
As any person that has already used Unity’s Ray class knows, there’s no support for reflection, which could be useful for some specific cases. This post will try to offer a solution to that, explaining how to create a script which casts a ray that gets reflected when it hits a surface. Not only that, but the script also allows to set the number of times the cast ray should bounce. An example project with a scene and the code explained below is available for download at the end of the tutorial.
Before looking how the reflection script works, a scene must be set with some walls to reflect the ray. Additionally, a game object will be required to act as the source of the ray . To create the ray’s source, just select GameObject->Create Other->Cube: (more…)
Unity: Normal Walker
Posted by Dimitri | Filed under Featured, Programming
This Unity programming tutorial explains how to create a controllable character that appears to ‘walk’ on the surface of another object. That’s achieved by using a script that matches the normal up orientation vector of the controllable game object with the surface normal of the other 3D object. But not only the script, this post also explains how to set up a scene to make it work.
A demo project with everything discussed here is available at the end of the post both in C# and JavaScript.
The first step is to create a Cube game object, that will act as your player. To do it, just select GameObject->Create Other->New Cube: (more…)
Unity: Throttle Controller
Posted by Dimitri | Filed under Programming
This Unity programming tutorial will explain how to create a script that translates the containing game object forward at a pre-defined speed rate. This rate is controlled by a throttle much like the ones found in boats, planes or even trains. As usual, a Unity project with a working demonstration of this code is available at the end of the post.
The inspiration behind this tutorial came from the first Half-Life game, in which a train at the end of the tutorial level can have its velocity is gradually set by the player. Some of you may not remember how it looked like, so here’s a screenshot: (more…)
Unity: How to make an overview map
Posted by Dimitri | Filed under Programming
This Unity tutorial explains the required steps to create a map that displays the level in a top-down view. For a real-time, precise map, an orthographic camera can be placed on the top of the map and set to exclusively render a specific layer. However, this post isn’t about creating a precise map, instead it shows how to create a stylized one. A Unity project with everything explained here is available for download at the end of this tutorial.
The first step is to create a plane by clicking on GameObject->Create Other->Plane. Resize it underneath your level, making it have the same size of your scene, not bigger or smaller, just enough to fit all of the elements inside it. (more…)
Unity: Scaling the GUI based on the screen resolution
Posted by Dimitri | Filed under Featured, Programming
As hinted by other posts, here, you will find how to properly scale the GUI elements based on screen resolution. As one may have noticed, Unity doesn’t scale the GUI elements based on the screen resolution, requiring a script to do the job, which is explained in this post. I will assume that the reader already knows how to create and render GUI elements in Unity using the MonoBehaviour’s OnGUI() function and GUISkin objects.
The best way to explain how to properly scale a GUI element is through an example. That said, for this post, let’s assume that we wanted a yellow rectangle to be rendered at the top left and bottom right corners of the screen, like this: (more…)