Dirso
19-11-2006 20:59:54
The Vehicle class can "run" in reverse speed?
Dirso
19-11-2006 20:59:54
syedhs
20-11-2006 10:16:05
for (std::vector<Vehicle::Wheel*>::iterator i = b;i != e;i++)
{
(*i)->update(power,desiredRpm, brake);
}
luis
20-11-2006 18:59:59
Dirso
20-11-2006 20:40:36
Dirso
21-11-2006 01:53:03
if (mID->isKeyDown(m_cThrottle))
{
m_bReverseSpeed = false;
}
else if (mID->isKeyDown(m_cBrake) && (_vehicle->getVelocity() <= 0))
{
m_bReverseSpeed = true;
}
if (m_bReverseSpeed)
{
_vehicle->setInputs( 0.0, -1.0, 0.0 );
}
else
{
_vehicle->setInputs( mID->isKeyDown(m_cLeft),mID->isKeyDown(m_cRight),
mID->isKeyDown(m_cThrottle), mID->isKeyDown(m_cBrake));
}
_vehicle->update(lTimeElapsed);
if (_camera)
{
// Thanks to Ahmed!
const Real followFactor = 0.2;
const Real camHeight = 2.0;
const Real camDistance = 7.0;
const Real camLookAhead = 8.0;
Quaternion q = _vehicle->getSceneNode()->getOrientation();
Vector3 toCam = _vehicle->getSceneNode()->getPosition();
toCam.y += camHeight;
toCam.z -= camDistance * q.zAxis().z;
toCam.x -= camDistance * q.zAxis().x;
_camera->move( (toCam - _camera->getPosition()) * followFactor );
_camera->lookAt(_vehicle->getSceneNode()->getPosition() + ((_vehicle->getSceneNode()->getOrientation() * Vector3::UNIT_Z) * camLookAhead));
}
luis
21-11-2006 07:54:57
Dirso
21-11-2006 08:55:21
luis
21-11-2006 20:08:54
void GBVehicle::_processInput( const FrameEvent& evt )
{
Real steering, sqrSpeed = mVehicle->getBody()->getLinearVelocity().squaredLength();
if( mInputDevice->isKeyDown(KC_J) )
{
steering = -1.0;
} else if( mInputDevice->isKeyDown(KC_L) )
{
steering = 1.0;
} else
{
steering = 0.0;
}
if( mInputDevice->isKeyDown(KC_K) && ( sqrSpeed <= 0.1 || !mDrivingForward ) )
{
mVehicle->setInputs( steering, -1.0, 0.0 );
mDrivingForward = false;
} else
{
mVehicle->setInputs( mInputDevice->isKeyDown(KC_J),mInputDevice->isKeyDown(KC_L),
mInputDevice->isKeyDown(KC_I),mInputDevice->isKeyDown(KC_K));
mDrivingForward = true;
}
}
Dirso
23-11-2006 21:04:57
Real sqrSpeed = _vehicle->getBody()->getLinearVelocity().squaredLength();
if (mID->isKeyDown(m_cThrottle))
{
m_bReverseSpeed = false;
}
else if (mID->isKeyDown(m_cBrake) && (sqrSpeed < 0.1))
{
m_bReverseSpeed = true;
}
if (m_bReverseSpeed)
{
_vehicle->setInputs( 0.0, -1.0, 0.0 );
}
else
{
_vehicle->setInputs( mID->isKeyDown(m_cLeft),mID->isKeyDown(m_cRight),
mID->isKeyDown(m_cThrottle), mID->isKeyDown(m_cBrake));
}
_vehicle->update(lTimeElapsed);
luis
24-11-2006 08:19:01
if i start moving the car stops if i press BRAKE but it doesn't start moving backward. But i don't really understand why if i start moving backward and press THROTTLE it stops and DOES start moving forward.
Dirso
25-11-2006 12:22:04
Dirso
25-11-2006 12:30:51
luis
25-11-2006 17:28:59
Could you help me reversing the torque curve with that code i post?
Dirso
25-11-2006 21:01:20
Absolutely. Find this line within OgreOdeVehicle.cpp
for (std::vector<Vehicle::Wheel*>::iterator i = b;i != e;i++)
{
(*i)->update(power,desiredRpm, brake);
}
Change desiredRpm to negative number.
Dirso
25-11-2006 21:57:18
luis
26-11-2006 11:21:00
The reverse speed only works if (a) the car is stopped in the beggining or (b) if it stops after collision
If it stops by itself (after losing power) or if I press BREAK again (even after it stopped by itself), it won't move backward.
Dirso
05-12-2006 22:34:45