8. December 2015

This tutorial came about as a result of a question on my YouTube channel, although it is one of those things that you are going to need to know before long in 3D game programming, so I have made the answer part of the official Godot Engine tutorial series.  The question was:

I am making a 3d game and I want to use a sort [of] top down style camera.

I want it so that if an object gets between the player and the camera, that same object will become transparent. For that ( I think ) I can use the "Use Alpha" function in the fixed material settings.
So I think I need a raycast shooting rays ( between the player and the camera ) and if it hits something it needs to "find' which object was hit en change the material settings so it becomes transparent.

Now, the problem is that I don't know how to set this up;
-how can I get which object is hit by the ray and how to change the material?
-do I need to create a separate layer for this?

This is one of those things even the most simple 3D game is going to encounter, but the solution isn’t obvious, although the questioner was extremely close in his guess.  You can solve this using Ray casting, it’s probably just the how of it all that is difficult to figure out.

As always there is a video version of this tutorial available here.

If you have a situation like the above, where you want to determine if something is in the way of your camera, it’s exactly RayCasting that you want.  Let’s take a look at how.

## Setting Up The Scene

First you need your scene to be set up correctly.  This means that each entity in your scene that can be collided with has to be a physics object of some kind.  I created the following scene arrangement:

As you can see, I have a camera and two Rigid Body objects, each with a CollisionShape (Cube) and a Test Cube child.  Additionally I created a RayCast object as a child of my camera.  Be sure to create the RayCast child before you transform your camera, so it is positioned properly.  For my RayCast I use the following settings:

My scene ends up looking like this:

## The Code

As you can see, the Ray extends from my camera and through both objects in the scene.  In this example we want to see if we hit the first cube (“RigidBody 2”) and if we do, we want to hide it.  Time to look at some code, the following script was attached to the camera:

```extends Camera

var ray = null

ray = get_node("RayCast")
set_process(true)

func _process(delta):
if(Input.is_key_pressed(KEY_UP)):
self.translate(Vector3(0,0.1,0))
if(Input.is_key_pressed(KEY_DOWN)):
self.translate(Vector3(0,-0.1,0))
if(ray.is_enabled() and ray.is_colliding()):
var collidedWithObject = ray.get_collider()
if(collidedWithObject.get_name() == "RigidBody 2"):
collidedWithObject.hide()
else:
get_parent().get_node("RigidBody 2").show()

```

… and that’s it.  We check to see that our ray is enabled and if it is currently colliding with something.  If it is, the first collided object is returned by the call get_collider().  In a bit of a hard coded hack, we check the name of that object, and if its our second cube, we hide the entire hierarchy.  In the event that no collision occurs, we make sure that RIgid Body 2 is visible with a call to Show().  You will notice that there is code in there to move the camera on press of the Up and Down arrow keys.  As you will see, as you move the camera, when the ray isn’t colliding, the second cube is shown, otherwise it is, like so:

It is also possible to create the ray programmatically using the PhysicsServer, like so:

```extends Camera

set_fixed_process(true)

func _fixed_process(delta):
if(Input.is_key_pressed(KEY_UP)):
self.translate(Vector3(0,0.1,0))
if(Input.is_key_pressed(KEY_DOWN)):
self.translate(Vector3(0,-0.1,0))

var directState = PhysicsServer.space_get_direct_state(self.get_world().get_space())
var collisions = directState.intersect_ray(get_translation(),Vector3(0,0,0))

if(collisions.size() and collisions["collider"].get_name() == "RigidBody 2"):
collisions["collider"].hide()
else:
get_parent().get_node("RigidBody 2").show()

```

Note that _process what changed to _fixed_process().  This is because space_get_direct_state() is only valid during _fixed_process or _integrate_forces() calls.  Otherwise we crate an intersect_ray() between the camera position and the origin, which in turn returns if there is a collision between those two points.  If there is, we hide the collided objects, otherwise we call show().

## The Video

8. December 2015

Unity Technologies just released version 5.3 of their popular Unity game engine.  The biggest news of this release is probably that WebGL is no longer an experimental platform and is considered a fully supported target.  Apple TV support is also coming soon, but as of right now it is in beta only.

The major bullet point features of this release are:

• New tools: A MonoDevelop upgrade, multi-scene editing, 2D tools and automated unit testing
• Graphics optimizations, including a new OpenGL core, experimental support for Metal in OS X, and an upgraded particle system.
• Coming soon: tvOS support
• Improved platform support for WebGL and iOS 9
• Integrated in-app purchase support
• VR improvements and new VR learning samples

There appear to have been major revisions to the Unity version of MonoDevelop including a streamlined UI and easier debugging as illustrated in this image:

Much more detail about the release is available here. Or you can download Unity 5.3 here.

7. December 2015

Last week I announced the Xamarin port of Urho3D to .NET and in the resulting /r/gamedev conversation it was discovered that the license it was released under required you to use Xamarin products.  This obviously caused a great deal of annoyance within the community.  Fortunately today Miguel de Icaza CTO at Xamarin announced that the license was a mistake at that it was being changed.

From the /r/gamedev conversation:

Hello lovers of Urho and .NET,

I just found out about this thread. It was not really our intention to annoy anyone, I used the license that was published as a blend of expedience and flexibility. It would have allowed me to decide when and where to license the code.

We have now released the source to our Urho bindings and put them under the MIT license:

The NuGet package still has the old license purely because I do not want to break all the samples (NuGet hardcodes a reference to the version in project, we still need to figure out a good strategy to release NuGet packages). But you can regenerate your own from the sources now.

Thanks to everyone that participated in this thread and voiced their opinion.

I can not wait to see what people do with this.

Miguel.

This is certainly a positive development and makes UrhoSharp useful to a much larger audience of developers.

4. December 2015

SideFx software just announced the release of Houdini Engine for Unreal.  Houdini is a long standing procedurally based 3D modeling, animating and rendering application which was until recently a fairly poor fit for game development.  With Houdini 15 they added the following game oriented features:

To enhance the creation of procedural game assets, Side Effects recently released Houdini 15 with new modeling and texturing tools. Modellers now have access to a new tweak edit workflow, edge sliding, soft selection highlighting and new tools such as PolyBridge and PolyExpand 2D – ideal for road generation. For working with hi-res models, new retopology tools make it easy to build low-res geometry by drawing right on top of high-res geometry.

“All of the modeling and texturing improvements in Houdini 15 have been developed with game artists in mind,” says Judith Crow, Director, Games Segment, Side Effects. “These tools can be used for interactive modeling in the viewport or to create procedural assets which can be loaded into the UE4 editor using the Houdini Engine plug-in.”

Houdini 15 also includes texture baking and viewport support for UDIM textures, world-space normal maps, UV mesh boundaries and overlapping UV regions. Game developers can now import and export tangent-space normal maps and convert bump and displacement maps to normal maps. For a complete list of Houdini 15 enhancements, go to www.sidefx.com/H15 and for tutorials go to www.sidefx.com/start_here.

Houdini Engine for Unreal is available now in Houdini Indie, Houdini and Houdini FX versions.  You can read more about the release here.

4. December 2015

Rarely do I weigh in on programming languages, I don’t think that C++ is better than Java, or vice versa.  Each fills a niche, even the much maligned Visual Basic was a very good programming language for what it did.

That all said, Objective C sucks.  I hated it, I hate it, I will always hate it.  Unfortunately until very recently it was the only game in town on iOS.  Well sure, you could use a 3rd party programming language like Java or C# and technically C and C++ were supported by Apple, if only weakly and in a half arsed manner.  But the official way, with all the tooling and documentation and other nice things programmers enjoy, it was ObjC or nothing.  Thankfully they recently released the Swift programming language.  Right after it was released I did a tutorial series on using Swift with SpriteKit and while not perfect, it was certainly a vast improvement over Objective C.  At the end of the day though, it was a single vendor and basically single platform language controlled by a company you’d have to be a bit daft to trust (with their developer track record…).

So yesterdays news came as a welcome surprise.  Swift is now open source. The source was released on Github under the Apache 2 license.  They also launched swift.org dedicated to the open source implementation of swift.

From the Swift blog:

Swift is now open source. Today Apple launched the open source Swift community, as well as amazing new tools and resources including:

• Swift.org – a site dedicated to the open source Swift community
• Public source code repositories at github.com/apple
• A new Swift package manager project for easily sharing and building code
• A Swift-native core libraries project with higher-level functionality above the standard library
• Platform support for all Apple platforms as well as Linux

Now anyone can download the code and in-development builds to see what the team is up to. More advanced developers interested in contributing to the project can file bugs, participate in the community, and contribute their own fixes and enhancements to make Swift even better. For production App Store development you should always use the stable releases of Swift included in Xcode, and this remains a requirement for app submission.

#### Swift.org

Swift.org is an entirely new site dedicated to open source Swift. This site hosts resources for the community of developers that want to help evolve Swift, contribute fixes, and most importantly, interact with each other. Swift.org hosts:

• A bug reporting and tracking system
• Mailing lists
• A blog dedicated to the engineering of Swift
• Community guidelines
• Getting started tutorials
• Contributing instructions
• Documentation on Swift
• Developer and API design guidelines

Swift.org is where the daily engineering work for Swift will take place, as the community of developers work together to bring Swift to new platforms, add new features, and continually evolve our favorite language.

#### Source Code

Apple has a new home on GitHub located at github.com/apple where you can find all the source code for the Swift project. The public repositories include the Swift compiler, LLDB debugger and REPL, the standard and core libraries, the package manager, and other supporting projects.

GitHub is already an incredibly popular place for developers to collaborate. It is easy to view the source code right on the website, or quickly check-out the code to your machine. And when you have a patch to contribute, we accept pull requests.

#### Swift Package Manager

Today we also launched a brand new project: the Swift Package Manager. This early-stage project will be developed in the open from the outset. The repository is in a very early state, and together we will define what a great package manager should do and how we can make it intuitive to use, and give it the power it needs to scale across the many platforms where we expect Swift to prosper.

#### Core Libraries

Apple has long provided a rich collection of frameworks that provide higher-level functionality commonly required across a wide variety of software. Frameworks such as Foundation, libdispatch, and XCTest make it much easier to write complex programs, and we wanted to be sure that developers get those same benefits as they take their Swift skills to new platforms. Whether writing apps for iPhone or Mac, or building a new cloud service on Linux, the Swift core libraries will give you building blocks you can count on.

#### Platforms

Open source Swift runs on a Mac, and is capable of building apps for OS X, iOS, watchOS, and tvOS. Swift.org also offers a Linux version of Swift, complete with a Linux toolset including package manager support, the LLDB debugger, and the REPL. We’re excited to see the community bring Swift to even more new places. As students and professionals learn to program in Swift, each new platform and use case opens new opportunities for them across the technology industry.

#### Getting Started

It is easy to get started. Swift.org hosts binary downloads of the compilers and command line tools for the Apple and Linux platforms so you can be up and running quickly. The latest version of Xcode supports an alternate toolchain option specifically designed to make it simple to try out the latest open source builds of Swift from within Xcode. And Swift.org has great getting started guides to walk you through the process of setting up your environment to work with open source Swift.

Let’s hope this gains traction, as anything that helps bury Objective C in the pages of history, is a very good thing indeed.