raidow
12-12-2011 16:54:52
Hi,
I'm using OgreBullet, and in order to move an object I use this method setLinearVelocity().
I use this one (and not applyForce, or applyImpulse) because I want that this object have a constant speed !
My problem is when I want to stop this object with setLinearVelocity(Ogre::Vector3::ZERO); I can't re-moving the object after...
My object is a car :
And after I do this in the frameRenderingQueued(const Ogre::FrameEvent& evt) of my FrameListener :
Result : my car moves, when the traffic light is red the car stops, but doesn't move again when the traffic light is green ! Do you know why or have you an alternative to do this ?
Thank you !
I'm using OgreBullet, and in order to move an object I use this method setLinearVelocity().
I use this one (and not applyForce, or applyImpulse) because I want that this object have a constant speed !
My problem is when I want to stop this object with setLinearVelocity(Ogre::Vector3::ZERO); I can't re-moving the object after...
My object is a car :
Ogre::SceneNode *car = mSceneMgr->getSceneNode("car");
Ogre::Vector3 car_scale = car->getScale();
Ogre::AxisAlignedBox boundingB_car = car->getAttachedObject("car_part16")->getBoundingBox();
Ogre::Vector3 size = boundingB_car.getSize();
size *= car_scale;
size /= 2.0f;
OgreBulletCollisions::CollisionShape *car_shape = new OgreBulletCollisions::BoxCollisionShape(size);
car_body = new OgreBulletDynamics::RigidBody("car", mWorld);
initialPositionCar1 = Ogre::Vector3(-2500.f, 40.0, mSceneMgr->getSceneNode("nodeRoad1")->getPosition().z+(75.0f));
initialOrientationCar1 = Ogre::Quaternion(Ogre::Quaternion(sqrt(0.5),0.0,sqrt(0.5),0.0));
car_body->setShape(car,car_shape, 0.6, 0.6, 1500.0, initialPositionCar1, initialOrientationCar1);
car_body->enableActiveState();
car_body->setLinearVelocity(speed_car, 0.0, 0.0);
mShapes.push_back(car_shape);
mBodies.push_back(car_body);And after I do this in the frameRenderingQueued(const Ogre::FrameEvent& evt) of my FrameListener :
//The variable called stop is an attribute of my listener
//Traffic Light
if(mSceneMgr->getEntity("tl1_red")->isVisible() && fabs(mSceneMgr->getSceneNode("tl1")->getPosition().x - node->getPosition().x) < 200.0f){
if(stop==false) car_body->setLinearVelocity(Vector3::ZERO);
if(mSoundMgr->getSound("carEngine")->isPlaying()) mSoundMgr->getSound("carEngine")->stop();
stop = true;
}
if(mSceneMgr->getEntity("tl1_green")->isVisible()){
if(stop==true) car_body->setLinearVelocity(speed_car, 0.0, 0.0);
if(!mSoundMgr->getSound("carEngine")->isPlaying()) mSoundMgr->getSound("carEngine")->play();
stop = false;
}Result : my car moves, when the traffic light is red the car stops, but doesn't move again when the traffic light is green ! Do you know why or have you an alternative to do this ?
Thank you !