Page 1 of 1

Physic for Space Game (walk at planets)

Posted: Sat Sep 12, 2015 2:20 pm
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

Re: Physic for Space Game (walk at planets)

Posted: Thu Sep 17, 2015 6:24 pm
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).

Re: Physic for Space Game (walk at planets)

Posted: Sat Oct 17, 2015 12:28 am
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.

Re: Physic for Space Game (walk at planets)

Posted: Mon Oct 26, 2015 3:48 pm
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