Move Body from point A to point B

Rambo

17-07-2007 14:21:56

I have world without gravity and I try move object in space.
This is my code, but is wrong.



//oblicz droge z punku A do B
m_Direction = m_NextPos - m_ShipNxBody->getGlobalPosition();
m_Distance = m_Direction.normalise();

Real move = (this->getSpeed() * elapsedTime)+1;
m_Distance -= move;

m_ShipNode->translate(move*m_Direction); <-- this is bad ??
m_ShipNxBody->setGlobalPosition(m_ShipNode->getPosition());

if (m_Distance<=0)
{
m_ShipNxBody->setGlobalPosition(m_NextPos);;
if (!m_WalkList.empty())
m_NextPosition=true;
else
this->m_ShipState=ShipState::SS_STAND_BY;
}


If I change this to addForce its work, but I don't know how to stop the ship.

betajaen

17-07-2007 16:48:52

For every action there is an opposite reaction. You need the opposite reaction to stop the ship. You should never move the node as well, not only it won't effect the body in anyway, but it'll put it back in the next frame.

You could however, use "mBody->moveTo(...)" which pretty much does the same thing as yours.

Rambo

17-07-2007 17:31:13

Ok.
I can't find vector of force.

Hmm.. I try this but don't work:


m_ShipNxBody->addForce(m_NextPos);// m_NextPos - Point B
if (m_Distance<=0)
{
Vector3 vel = m_ShipNxBody->getLinearVelocity();
Real mass = m_ShipNxBody->getMass();
m_ShipNxBody->addForce(-(m_NextPos+(vel*mass)));

if (!m_WalkList.empty())
m_NextPosition=true;
else
this->m_ShipState=ShipState::SS_STAND_BY;
}


What "addForce" change or what I have get from Body ?

betajaen

17-07-2007 19:05:36

Did you try mBody->moveTo(..) like I suggested, it keeps in account of distance and alters the force by it?

Rambo

17-07-2007 19:53:37

Well, moveTo is in 0.6. I try moveTowards and ..hmm... it's weird.

addForce trajectory is line.
moveTowards trajectory is random something.

I think I must change this to Ray and use setGlobalPosition.