Newton Vehicles in Irrlicht Tutorial

A forum to store posts deemed exceptionally wise and useful
Nick_Japan
Posts: 98
Joined: Mon Dec 13, 2004 11:47 am
Location: Japan

Newton Vehicles in Irrlicht Tutorial

Post by Nick_Japan »

Hey all,

I wrote a simple tutorial for getting Newton Vehicles into Irrlicht - it's not the best programming you've ever seen but I think it's a nice starting point.

http://www.nick-online.co.uk/dev/vehicle_tutorial.zip

Hope it's useful!
omaremad

Post by omaremad »

thanx alot i ve been struggling to make newton car s work
cassini
Posts: 68
Joined: Thu May 12, 2005 2:40 pm

Post by cassini »

Wow I just played this tutorial, and you car setup have a very nice driving feel, very nice.
the user
Posts: 6
Joined: Sun Mar 20, 2005 7:47 pm

Post by the user »

Hey good work!
phi

Post by phi »

Thank you!!! :D
rangle
Posts: 6
Joined: Fri Sep 17, 2004 5:27 am
Location: California, USA
Contact:

Post by rangle »

VERY GOOD! I especially like the tuning on the car. Too many of these physics demos have cars that are uncontrolable. This one behaves a bit like an RC car, which I wanted.

I've messed around in the code and got the wheels to stay above the ground a bit better if the global Newton2Irr value is less than 32.0f.

For anyone who has used this code - I am not sure why the ramps don't seem to work as expected if you switch to blockland_jumps.obj. Maybe something isn't hooked up correctly in the physics collision.

I'm also still trying to turn on some textures... the monochrome world just doesn't work for me ;-)

Cheers,
rangle
Nick_Japan
Posts: 98
Joined: Mon Dec 13, 2004 11:47 am
Location: Japan

Naming fix

Post by Nick_Japan »

Heya all, glad you're all having a good time with it! Rangle, regarding the blockland_jumps problem, yeah the car never did whizz over them really. The only thing it really shows is that if you drive along with two wheels on the ramp and two still on the ground you can really see the suspension bouncing. I think one of the reasons the car doesn't really jump is that the default one that I set up is front wheel drive, which is partly what gives it the nice handling. What this means is that the moment the front wheels leave the ramp, there's nothing pushing the car forward as the drive wheels are spinning in mid-air, and so it just slows and flops down.

WHOAH! Sorry - was just looking at my code - has anyone else seen that the wheel naming is way off? OK - just fixed it. wheel_FR is the Front Right wheel, wheel_RL is Rear Left and so on. The link above now downloads the fixed version.

Anyway, in driveCar() change:

Code: Select all

    if(bus->physics->PLAYER_MOVE_FORWARDS)
    {
        bus->physics->car->wheel_FL->torque = 50.0f;
        bus->physics->car->wheel_FR->torque = 50.0f;
    }
    else if(bus->physics->PLAYER_MOVE_BACKWARDS)
    {        
        bus->physics->car->wheel_FL->torque = -50.0f;
        bus->physics->car->wheel_FR->torque = -50.0f;
    }
    else if(!bus->physics->PLAYER_MOVE_BACKWARDS && !bus->physics->PLAYER_MOVE_FORWARDS)
    {                
        bus->physics->car->wheel_FL->torque = 0.0f;
        bus->physics->car->wheel_FR->torque = 0.0f;
    }
to:

Code: Select all

    if(bus->physics->PLAYER_MOVE_FORWARDS)
    {
        bus->physics->car->wheel_RL->torque = 50.0f;
        bus->physics->car->wheel_RR->torque = 50.0f;
    }
    else if(bus->physics->PLAYER_MOVE_BACKWARDS)
    {        
        bus->physics->car->wheel_RL->torque = -50.0f;
        bus->physics->car->wheel_RR->torque = -50.0f;
    }
    else if(!bus->physics->PLAYER_MOVE_BACKWARDS && !bus->physics->PLAYER_MOVE_FORWARDS)
    {                
        bus->physics->car->wheel_RL->torque = 0.0f;
        bus->physics->car->wheel_RR->torque = 0.0f;
    }
to set it to rear-wheel drive. The handling's not nearly as good, but you can get a bit more of a jump. I prefer front-wheel drive though. Happy tinkering!

EDIT: About the ramps not working - stupid question - you did change both loading lines in main(), right? There are two calls - one which loads the scenenode and another which actually loads the physics mesh - you need to change both
the user
Posts: 6
Joined: Sun Mar 20, 2005 7:47 pm

Post by the user »

Hi,
i think

Code: Select all

if(bus->physics->PLAYER_MOVE_FORWARDS) 
    { 
        bus->physics->car->wheel_FL->torque = 100.0f; 
        bus->physics->car->wheel_RR->torque = 100.0f; 
    } 
    else if(bus->physics->PLAYER_MOVE_BACKWARDS) 
    {        
        bus->physics->car->wheel_FL->torque = -100.0f; 
        bus->physics->car->wheel_RR->torque = -100.0f; 
    } 
    else if(!bus->physics->PLAYER_MOVE_BACKWARDS && !bus->physics->PLAYER_MOVE_FORWARDS) 
    {                
        bus->physics->car->wheel_FL->torque = 0.0f; 
        bus->physics->car->wheel_RR->torque = 0.0f; 
    }
is right.
Because the other have small right or left drift.
Or?
Nick_Japan
Posts: 98
Joined: Mon Dec 13, 2004 11:47 am
Location: Japan

Post by Nick_Japan »

Sorry - I've not been very clear about this one. I got the names of the wheels and the locations of the wheels a bit muddled up in the original code. Just to get us all on the same page - in assembleCarPhysics() make sure your wheel declaring looks like this: (Make sure the coordinates are right)

Code: Select all

    wheel_FL = new CPhysicsCarWheel();
    wheel_FR = new CPhysicsCarWheel();
    wheel_RL = new CPhysicsCarWheel();
    wheel_RR = new CPhysicsCarWheel();
    wheel_FL->rigupPhysics(vehicle, -6.0f * IrrToNewton, 0.0f * IrrToNewton, -4.0f * IrrToNewton, wheel_FL, 1);
    wheel_FR->rigupPhysics(vehicle, -6.0f * IrrToNewton, 0.0f * IrrToNewton,  4.0f * IrrToNewton, wheel_FR, 2);
    wheel_RL->rigupPhysics(vehicle,  6.0f * IrrToNewton, 0.0f * IrrToNewton, -4.0f * IrrToNewton, wheel_RL, 3);
    wheel_RR->rigupPhysics(vehicle,  6.0f * IrrToNewton, 0.0f * IrrToNewton,  4.0f * IrrToNewton, wheel_RR, 4);
OK - now wheel_FL is actually the Front Left wheel, wheel_RR the Rear Right wheel, and so on. Sorry about all that. Now driveCar() makes a bit more sense - in order to steer with the front wheels, change the angle of wheel_FR and wheel_FL. In order to drive with the rear wheels, add torque (NOTE: possibly BAD Newton usage!) to wheel_RL and wheel_RR, and so on.
I hope that's cleared all that up.

@the user - yes very possibly your code is right if you're still using my original code with the wheel names muddled up - I'd recommend fixing it though because what you're code looks like it's doing is driving the car with the Front Left and Rear Right wheels.
Joe_Oliveri
Posts: 448
Joined: Tue Oct 05, 2004 3:24 am
Location: Boston, MA

Post by Joe_Oliveri »

thats very nice, and I was having fun till I went off the cliff. Nice tutorial! :)
Irrlicht Moderator || Game Designer
Learn the basics at </dream.in.code>
ry
Posts: 8
Joined: Mon Dec 12, 2005 4:15 am
Contact:

Post by ry »

Its a great demo, but everytime i go to compile the source code i get something like 50 errors, with the code untouched. I'm almost positive that the demo was made for 0.12.0, ive got 0.14.0. If that's the case any chance of an update? If it was made for 0.14.0 then it just must be my compiler or something of the sort
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

neato burrito!

thnx Nick_Japan :wink: Nice implementation of physics. I love the "inertia" in the car.
Oziriz
Posts: 22
Joined: Wed Oct 12, 2005 6:44 pm

Post by Oziriz »

Just want to let everyone know that the suspension has changed severely in Newton 1.5, so this won't work with that anymore. I still use Newton 1.32 in Mystery but if anyone wants to try this one with 1.5 these changes need to be made:

- Remove the wheel balancing, it's not used in Newton 1.5 anymore
- All wheels are now (void *) instead of (int)
- Suspension now uses higher values, here's a sample code:

Code: Select all

      tireMass = 5.0f;
      tireSuspensionLength = 0.05f;
      tireSuspensionSpring = mass / tireSuspensionLength;
      tireSuspensionShock = 2 * sqrt(tireSuspensionSpring);
Where mass is the mass of the vehicle. :) All credits go to Nick_Japan, because without him I wouldn't have started writing my own car implemention for Newton.
If you need any further help with vehicles in Newton you can contact me via PM and I'll answer as soon as I can.
Nick_Japan
Posts: 98
Joined: Mon Dec 13, 2004 11:47 am
Location: Japan

Post by Nick_Japan »

I've having some trouble porting my vehicle code to Newton 1.5. For some reason, the wheels don't seem to update or collide or anything, the car's body simply falls and lands on top of the ground, as if it was a solid box. Furthermore, the wheel's update code doesn't seem to get called at all; they don't spin if I add torque to them and in fact their callback never gets run. Has anyone managed to get vehicles working nicely in 1.5? What did you have to change? From my original tutorial, all I've changed is to update the tyre pointers from ints to void * where applicable.
dhenton9000
Posts: 395
Joined: Fri Apr 08, 2005 8:46 pm

Post by dhenton9000 »

Nick_Japan wrote:I've having some trouble porting my vehicle code to Newton 1.5. For some reason, the wheels don't seem to update or collide or anything, the car's body simply falls and lands on top of the ground, as if it was a solid box. Furthermore, the wheel's update code doesn't seem to get called at all; they don't spin if I add torque to them and in fact their callback never gets run. Has anyone managed to get vehicles working nicely in 1.5? What did you have to change? From my original tutorial, all I've changed is to update the tyre pointers from ints to void * where applicable.
the only thing I can think of is Julio's big time warning about how everything dies when its outside of the world size, a new feature of 1.5
Post Reply