Physic for Space Game (walk at planets)

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
Feuerstern
Posts: 7
Joined: Mon Aug 17, 2015 4:04 pm

Physic for Space Game (walk at planets)

Post by Feuerstern »

Hello
I am actual making a space game where the player is on a little planet. Because the Planet is round and the the player should go all over the planet, the planet must pull the player at it. So it must have a own gravity.
At this moment I dont have implemanted any Physic Engine. (Iam thinking about Newton or Bullet)
Do anyone now a physic engine which can handle this sort of gravity? Or can I easiely implement it in irrlicht itself?

Thanks for help
Feuerstern
sunnystormy
Posts: 105
Joined: Mon Jun 02, 2014 2:32 am
Location: Washington, D.C.
Contact:

Re: Physic for Space Game (walk at planets)

Post by sunnystormy »

Hi, Feuerstern.

There should be several tutorials on physics integration at:

http://irrlicht.sourceforge.net/tutorials/

Look towards the bottom of the page, and you should find several options available (I believe Newton is included as well).
My blog: http://fsgdp.wordpress.com "The Free Software Game Development Pipeline"
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Physic for Space Game (walk at planets)

Post by devsh »

All larger physics engines (Bullet, PhysX) implement "force fields" which are ideal for gravity.

Just be aware to not add to many objects with "gravity" because you'll soon turn this into an N-Body problem which is a task for supercomputers.
joelCañas
Competition winner
Posts: 7
Joined: Tue May 19, 2015 1:27 pm
Location: Mérida - Venezuela

Re: Physic for Space Game (walk at planets)

Post by joelCañas »

Hi Feuerstern.

If you just need to keep your characters walking around the planet and not shoot boxes or drop objects, may be you can use this approach I used in my little simulation of a planet.
Image

I'm using this code for moving my characters around the planet:

Code: Select all

void update()
{
    //set the character position on the planet, without rotations
    CharacterNode->setPosition(AIEntity->getAbsolutePosition());
 
    //get the actual position
    irr::core::vector3df curPoint = CharacterNode->getPosition();
    //get the destination position (this is using irrAI but it can be ported to another navigation system)
    irr::core::vector3df nextPoint = ((INPC*)AIEntity)->getCurrentWaypoint()->getPosition();
 
    //set the Z direction
    irr::core::vector3df worldDirection(0,0,-1);
 
    //and the Y direction
    irr::core::vector3df inverseUp(0,-1,0);
 
 
    irr::core::vector3df masterUp = curPoint - inverseUp;
    masterUp.normalize();
 
    //this is the direction vector, with this, we calculate the others rotations
    irr::core::vector3df masterDirection = nextPoint - curPoint;
 
    irr::core::vector3df realDirection = masterUp.crossProduct(masterDirection).normalize();
    realDirection = realDirection.crossProduct(masterUp);
 
    irr::core::quaternion quatDirection;
    quatDirection.rotationFromTo(worldDirection, realDirection);
 
    irr::core::vector3df worldUp(0,1,0);
 
    irr::core::matrix4 mat;
    quatDirection.getMatrix(mat);
    mat.rotateVect(worldUp);
 
    irr::core::quaternion quatUp;
    quatUp.rotationFromTo(worldUp,masterUp);
 
    //merge the rotations in one
    irr::core::quaternion quatAll = quatDirection * quatUp;
 
    irr::core::vector3df eulers;
    quatAll.toEuler(eulers);
 
    //convert the quaternions in eulers
    eulers *= irr::core::RADTODEG;
    CharacterNode->setRotation(eulers);
}
 
I hope it can be usefull
Post Reply