Thursday, October 21, 2010

Game Engine Ideas

I believe that introducing force will save a lot of time when working on effects or with the environment. Then we can introduce some more interesting game-play with puzzles. The only difference from the version we have now is that you put a Newton law between and calculate position and speed by it.

// this would be inside your Movable class (or defined by interface)
public void Move(float time)
{
position += velocity * time;
velocity += _force * inverseMass * time;
}

public void AddForce(Vector3 force)
{
_force += force;
}

public void ClearForces()
{
_force = Vector3.Zero;
}

Then from your game class inside your Update() you would just apply to certain (or to all, or to just one) Movable objects a force... this force can be anything... then if there are no forces it would just not move or stay moving in constant speed.

// Inside Update()
//whatever objects you decide to act force on
foreach (GameObject enemy in enemies)
{
//whatever force you decide
enemy.AddForce(GetGravityAt(enemy.position));
enemy.Move( 0.001f);
enemy.ClearForces();
}

aside from the movable class there would be collidable one making sure that everything explodes or bounces properly if their bounding boxes collide...

Some examples of use:

  1. ship's racket engine - just applying force in direction you want to move or in the opposite to break. Here is the example please notice how there is a lag when firing the engine and how the movements of the ship are smooth - this would not be possible without using forces http://eng.utah.edu/~dusatko/CS1410-EAE/asteroids.html (CS1410 class, forces used)
  2. simple AI - you can code it the way that your ship's position vector is passed to your enemies, enemy class then calculates its direction vector to your position and applies it as a force. If the enemy is already passing by your ship it will start circling around you, then if it gets to certain distance it can start shooting at you (you decide). Here is the example, sharks get the force applied so they are circling around you http://eng.utah.edu/~dusatko/CS2420-EAE/finalProject.html (CS2420 class, forces used)
  3. Tractor beam - lets say you want to pull some asteroid, just aim and push the button, this would create some long 3d cylinder object starting from you and if it touches your chosen asteroid then it would have a collision with it and trigger adding some force to it in your direction
  4. Sticky nebula - this would be position dependent, if you get between certain coordinates in whatever direction you are moving the small force (smaller then your engines have) would act in opposite direction of your velocity. This would go for all movable objects that get to this sticky area.
  5. Black hole - this would be also position dependent, once you create a black hole it will check the nearest objects and add forces to them so they move to it. There would be some effect when they collide with the actual bounding box of the black hole.
I believe we can come up with many more ideas how to use this force. I think it is ok without the forces but all effects will not come so naturally and we may actually spend more time just figuring them out how to do some hacks to the game
engine.

No comments:

Post a Comment