Reverse speed

Dirso

19-11-2006 20:59:54

The Vehicle class can "run" in reverse speed?

syedhs

20-11-2006 10:16:05

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.

luis

20-11-2006 18:59:59

you can call:
Vehicle::setInputs( steering, -1.0, 0.0 );

but the torque curves will be wrong (inverted).

Dirso

20-11-2006 20:40:36

It worked!!!! Thanks a lot again!!!!

Dirso

Dirso

21-11-2006 01:53:03

This code works fine if the car is stopped. By if it's moving forward, it won't stop to get reverse speed.
I did this piece of code, but it doesn't work too:
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));
}

Any ideas about what I'm doing wrong?

Thanks a lot,
Dirso

luis

21-11-2006 07:54:57

If you want i can copy-paste the code i have when i get home, but (in my code) reverse only works when you holds the break key and the car is stoped.....

Dirso

21-11-2006 08:55:21

It would be great!

Thanks a lot,
Dirso

luis

21-11-2006 20:08:54

here goes:


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;
}
}


good luck ;)

Dirso

23-11-2006 21:04:57

I really don't understand what is happening :cry:
You code is almost the same as mine, and the car only run in reverse speed if it is stopped, 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.
Do you have any ideas?
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.

you are right... i don't know either :(
we should see what's doing OgreOde internally, and also revert the torque in reverse.....

May be another solution would be to just reverse the torque curve setting the values with negative numbers. This is not a realistic solution but may fix all those problems.

Dirso

25-11-2006 12:22:04

Is that a bug?

Dirso

25-11-2006 12:30:51

Could you help me reversing the torque curve with that code i post?

Thanks for all your help,
Dirso

luis

25-11-2006 17:28:59

Could you help me reversing the torque curve with that code i post?


i tried reverting the torque in my code but it didnt work :(

anyway the current behavior is ok to me, i think the player *must* press again the break key to go on reverse.....

EDIT: try what syedhs said

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.


I didn't use it because I have no idea how. Could anyone help me?

Thanks a lot!

Dirso

25-11-2006 21:57:18

I don't know about your application but for me there is something wrong.
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.

Thanks a lot,
Dirso

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.


It doesn't happen with the code i posted and after reading your code i dont see anything wrong there (but i didn't compile it...).
Debug your application, use printfs ;) or just adapt the code i sent to you and see if the problem is still there.

Dirso

05-12-2006 22:34:45

Your code really worked and i don't know what i did wrong :(
Anyway, I think it is not a good way to do that asking the player to press BREAK again to move backward.
Thinking about the ogre or the ode internal code what is the diference between keeping the BREAK key pressed or pressing/releasing/pressing again the BREAK key?

If anyone could explain me that i'll try to figure out how to make it work.

Thanks a lot,
Dirso.