Posts Tagged ‘JavaScript’

These posts contain JavaScript code or are somehow related to JavaScript.

Unity3D: Programming a machine gun – Part 1

Click here to read Unity3D: Programming a machine gun – Part 1

This is the first of two posts that will explain how to program a machine gun at the Unity3D game engine. This post will focus on coding the element that defines a weapon of this type: continuous automatic firing. It will show two different ways to achieve this behavior: one based on the Invoke() method call, and the other based on Unity3D’s coroutines. As any other post series in this website, a Unity3D project with all the source code will be available at the last post of the series.

All code in this post will be in C#, but for those who don’t use it, a JavaScript version of the code will be available for download at the end of the post.


Unity3D: Troubleshooting Rigidbody problems

Click here to read Unity3D: Troubleshooting Rigidbody problems

Maybe the component that give Unity3D developers the most number of headaches is the Rigidbody. Sometimes it doesn’t seem to not work the way it’s supposed to, although these problems are mostly caused by wrong parameter values and settings. That’s the main reason behind this post: to point out the most common problems encountered when using rigidbodies in Unity3D.

Before listing these problems, keep in mind that the Rigidbody is part of the physics simulation in Unity3D which is decoupled from the game logic, and that’s why there is a separated Physics Time Step and a different method dedicated to it- the FixedUpdate() method. And before trying to figure out what the problem is, check the basics and see if all GameObjects the Rigidbody collides with have an attached Collider component, or if some parameter is set too high or too low.


Unity3D: JavaScript vs. C# – Part 5

Click here to read Unity3D: JavaScript vs. C# – Part 5

As the end of the year draws close, so is this post series. Here, the differences between JavaScript and C# when casting a ray in Unity3D will be pointed out. Don’t forget to read the first, second, third and forth parts of the series for a better general understanding of what is being discussed here.

Let’s start from the basics: What is ray casting? As the name describes, it is basically a program that simulates a ray being cast, much like a laser pointer in real life. It is very useful for game programming, as Raycast classes are programmed to return the distance a ray collided with something (and sometimes, even the name of the object). Unity3D doesn’t have one single Raycast class, instead its functionality is scattered across the Physics, RaycastHit and Ray classes.


Unity3D: JavaScript->C# or C#->JavaScript access

Click here to read Unity3D: JavaScript->C# or C#->JavaScript access

When programming for Unity3D, there are some cases where we need to access a script written in another programming language that isn’t the one we are currently using. Although it is highly recommended to convert all scripts to the same one, it is useful to know how to access a C# script from a JavaScript class and the other way around.

The first thing to do is place the scripts in the correct folders in your Project tab. The script you want to have access must be inside the Standard Assets or the Plugins folder. The other script has to be placed outside these folders. After this step, just call the GetComponent() method as any other Component. Here’s a JavaScript example: (more…)

Unity3D: JavaScript vs. C# – Part 4

Click here to read Unity3D: JavaScript vs. C# – Part 4

This is the 4th post of a series that tries to explain the main differences between JavaScript and C# when programming for Unity3D. In this post, some differences between yielding (pausing) code execution in these two programming languages will be pointed out. Before continuing, it is highly recommended that you read the first, second and third other posts of the series.

As explained before, yielding pauses the code execution, being very useful to game programming, as you have a better control when things will happen in your game. Whether using C# or JavaScript in Unity3D, one can’t simply yield the Update() method. There is a workaround for that, but as you might have guessed, they are different for the two programming languages we are discussing. Since these workarounds are often used, they will be the examples presented on this post. Let’s start by seeing how to yield a JavaScript code: (more…)