Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualDishSoap

Posted 04 June 2013 - 03:21 PM

For projectiles you are going to want to have an acceleration, velocity and position vector. I would argue for all physical objects in your world you will want these three vectors and integrate them according to some law such as Euler or RK4.

 

When I create my games I tend to have some base class, "MoveableObject" or PhysicalObject, that simply holds these three vectors and is responsible for integrating them.

 

class MoveableObject
{
public:
    integrate(dt)
    {
        position += velocity * dt;
        velocity += velocity + acceleration * dt;
    };

    Vector2 position;
    Vector2 velocity;
    Vector2 acceleration;
};

 

If you choose to add gravity to your projectile all you'd have to do is set the acceleration vector accordingly.

 

This way every moving object in your world has some base object you can access these variables by. A projectile would have this as a base class and would simply be integrated just like any other moving object in your would.

 

Here is a great article on it! http://gafferongames.com/game-physics/integration-basics/


#1DishSoap

Posted 04 June 2013 - 03:20 PM

For projectiles you are going to want to have an acceleration, velocity and position vector. I would argue for all physical objects in your world you will want these three vectors and integrate them according to some law such as Euler or RK4.

 

When I create my games I tend to have some base class, "MoveableObject" or PhysicalObject, that simply holds these three vectors and is responsible for integrating them.

 

class MoveableObject
{
public:
    integrate(dt)
    {
        position += velocity * dt;
        velocity += velocity + acceleration * dt;
    };

    Vector2 position;
    Vector2 velocity;
    Vector2 acceleration;
};

This way every moving object in your world has some base object you can access these variables by. A projectile would have this as a base class and would simply be integrated just like any other moving object in your wourld.


PARTNERS