Genesis – Phase II Complete – Physics

Posted: July 30, 2013 in Game Programming and Design

The screenshot remains the same as in phase 1, only this time we added some physics to the mix to bounce the ship off of it.  This took a little bit of playing around…



The first thing that I had to do was get my ship model loaded in.  I’m using the basic ship from the Direct X SDK that Microsoft provides.  This is just a basic model… added a reflective material to the surface.  Spent time positioning the camera over the cockpit (and in the bottom render you can see the nose of the craft) and then added mesh colliders to both the ship and the space station.

The majority of this phase was figuring out Unity and how to get colliders to work.

I set the station and the ship to both have a collider, to have rigid bodies, and to not be kinemetic.  This was very important… as this is how the OnCollision trigger is fired.  If the colliders are kinemetic then you must use the trigger properties instead, which I chose to not implement because I actually want my ship to be able to collide with things and not necessarily destroy them.

Once that was done I created a new script called “ShipPhysics” and added that to my ship (the motor script is attached to the camera, that may be changed in the future but for right now the camera still controls the movement of the parent body).  I inserted a simple event handler that would check the tag of the object I collide with, and if its a space station, to run a custom method to end my app if my current speed is over 40m/s.

private void OnCollisionEnter(Collision collision)
//rigid bodies collided
if (collision.gameObject.tag == TAG_STATION)

private void CollideWithSpaceStation()
//if current speed is slow, nudge the station
//if current speed is not slow, the ship will be destroyed for right now
if (this.GetComponentInChildren<Ship>().CurrentSpeed > 40)
Debug.Log (“Quitting”);
Application.Quit ();

Testing the code confirms that it works.  I can now fly around the station and run into it and it bounces my ship off of it, and if over 40 m/s will end the app (blowing me up)

Now I need to start constructing a GUI…



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s