Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Genesis Phase II complete - physics on the ship to station collision

Sign in to follow this  


[font=arial]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...[/font]


[font=arial]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.[/font]

[font=arial]The majority of this phase was figuring out Unity and how to get colliders to work.[/font]
[font=arial]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.[/font]

[font=arial]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.[/font]private void OnCollisionEnter(Collision collision){//rigid bodies collidedif (collision.gameObject.tag == TAG_STATION){CollideWithSpaceStation();}}private void CollideWithSpaceStation(){//if current speed is slow, nudge the station//if current speed is not slow, the ship will be destroyed for right nowif (this.GetComponentInChildren().CurrentSpeed > 40){Debug.Log ("Quitting");Application.Quit ();}}
[font=arial]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)[/font]

[font=arial]Now I need to start constructing a GUI...[/font]
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!