Sign in to follow this  

Modelling a spaceship with OOP

This topic is 4187 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm about to start writing a simple game - similar to asteriods only 3d. My main aim is to build a system whereby users will be able to configure their ships i.e. place engines where they want and add weapons where they want. I'm going to write it in C# using oop. These are my thoughts: A ship has a hull, which has mass and a center of mass. A spaceship can host many engines. Each engine provides x amount of thrust. An engine can be placed at any location upon the hull of the ship. The location of the engines upon the hull will be read from an xml file which will define the ship in question - i.e. the gamer will be able to script my vessels. The hull is aware of its position, orientation, mass and center of gravity. The engine is aware of its position and orientation upon the hull. So - I imagine the ship object should have a collection of engine objects If I want to fire a port engine rather than a starboard engine, I have to iterate over the objects and determine which are on the left of the ship and which are on the right, before calling the engine.Fire method This seems rather silly. How would you approach this?? I would also like to abstract this model of the ship from the rendering engine - what design patterns would you suggest? Many thanks for your help!!

Share this post


Link to post
Share on other sites
Quote:
Original post by keepoffthegrass


If I want to fire a port engine rather than a starboard engine, I have to iterate over the objects and determine which are on the left of the ship and which are on the right, before calling the engine.Fire method


You need to know how you want to allow the player to operate the engines. The approach I'm about to suggest is extendible to whatever collection fo firing options you want but I'm just going on the assumption of Fire_Port, Fire_Starboard, Fire_All.

I'm assuming that the engines can't move around the ship once the ship has been generated. That means you can determine which side of the ship they're on on generation of the ship. As each engine is added it can be placed in a port or starboard collection. Whenthe player wants to Fire_Starboard the program simply has to iterate through and activate all the engines in the starboard collection.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
A good suggestion!

Okay, an engine will have a position and an orientation relative to the ships center (which we will assume is the ships center of mass).

If an engine is positioned on the right hand side of the ship (and firing to the right) the ship will move right i.e


..........
. .
E....... C .......E
. .
..........


Where C is the center of mass of the ship and E is an engine - this is a top down view of my ship

However in the following situation, where the engine is above the center of mass, the ship will rotate about the center of mass (clockwise).


..........
. .
. .
. C .
E....... .......E
. .
..........


This means I will need to determine the x and y axis thrust components with regard to the center of mass (in case 1, x=thrust, y=0 in the second case)

Should the engine be responsible for working out the thrust and vectors and the ship be responsible for working out its rotation/motion?

How would you approach this?

[Edited by - Shannon Barber on July 5, 2006 8:04:48 PM]

Share this post


Link to post
Share on other sites
My diagrams didnt work!!!

the key question is:

should the engine be responsible for working out the physics?

Or should this be handles externally from the ship??


[Edited by - keepoffthegrass on July 4, 2006 5:05:53 AM]

Share this post


Link to post
Share on other sites
Hey man i don't exactly get it but maybe this might help. I'm doing a space ship game myself. From your example, The ship knows all the engine attachment points along with their orientations mass thrust etc. So the ship could grab this info from all the engines mash this up with its internal info and other factors and calculate some results for the world to see. Hope this makes since. I'm sure some others have some good info as well.

quack


[edited period]



Share this post


Link to post
Share on other sites
I would let the user define his own keys. Lets name three engines A, B and C. The player can define how much trust from each engine you will get from each key. Lets say he wants Key1 to be 4 kg*m/s (is that the notation for thrust?) from engine A, 2 from engine B and 1 from engine C. Then he'll be able to define new types of keys later. This way the player can define a left turn, a right turn or a strafe himself. And of course maybe he want some really odd spin for all I know.

If the keys are actually keyboard keys, different engine options or keys on the user interface is up to the game designer. So is the decision if the user should order pulses or streams from the engine, in otherwords if the user should ask for a one time engine boost or to just turn the engine on.

Sounds like a fun project, I hope to hear more about it!

Share this post


Link to post
Share on other sites
The way my team is doing it is like this.

Yes, you can "attach" engines, weapons, etc to the hull of a ship. Each engine attached (based on the engine's type data etc) adds thrust to the ship.
My physics works on the ship as a whole, using the sum of thrust from all engines. We are going to give the "pilot" the benefit of the doubt that he/she can fly straight even if the engines are mounted, say, on the bottom of the ship pointing behind the ship. (in real life, the ship would need counter thrusters to keep it straight).

Share this post


Link to post
Share on other sites
Sign in to follow this