irrNewt - moving a tank

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
death_au
Posts: 38
Joined: Tue Apr 17, 2007 9:48 am
Location: Australia

irrNewt - moving a tank

Post by death_au »

I've been playing around with irrNewt to get some decent physics into a small game I'm making which involves controlling a tank. I've been looking at the vehicle tutorials for both irrNewt and Newton itself, but not finding what I want.
What I want is a type of movement and steering with my tank as follows:
There are two buttons only to control the tank (eg. left and right). When you press the left button, the left wheels spin, and when you press the right button the right wheels spin. This means that if you wish to go forward, you have to press both left and right. Also if you want to turn right, you only press left, and if you want to turn left, you only press right.
Later on there will be more inputs so that you can spin each wheel backwards as well, but I'm just starting simple.
I thought it would just be as easy as applying tourqe to one side's wheels when you press the correct button, but the vehicle still seems to just go straight anyway.
Does anyone have any ideas on how to get this to work properly?
JonLT
Posts: 152
Joined: Thu Mar 15, 2007 5:47 pm
Location: Denmark

Post by JonLT »

Maybe making some kind of axel friction so that the wheels on the other side doesn't just roll along with no problem or maybe making the wheels unable to roll onless a key is pressed?
death_au
Posts: 38
Joined: Tue Apr 17, 2007 9:48 am
Location: Australia

Post by death_au »

JonLT wrote:Maybe making some kind of axel friction so that the wheels on the other side doesn't just roll along with no problem or maybe making the wheels unable to roll onless a key is pressed?
I tried setting the wheels on the opposite side to brake, but that just means the vehicle is trying to move with the handbrake on. It is turning, but waaaaaaaay too slow.
I'm quite new to Newton and IrrNewt, so I think putting the handbrake on my not be the best way to stop a wheel from rolling. Don't know anything about the axel friction either.
olivehehe_03
Posts: 157
Joined: Tue Mar 20, 2007 8:30 am

Post by olivehehe_03 »

I've been trying something similar with getting a tank to work, and I noticed that simply adding torque to the wheels on the left or right didn't work either. I think the problem is that the wheels are still facing forwards, so even if you add torque to one side, it's still rolling on the wheels on the other side so it will go forward. I've tried turning the wheels on one side one way and the wheels on the other side the other way, but it either doesn't turn at all, or it turns way too slow to be practical. Just so you know I've got my tank setup as a newton::IVehicleSimple with 8 wheels :D

One of the ideas I've come up with is turning certain wheels (not adding torque, but using setSteerAngle()) so that the tank can actually turn, even if that's not how a tank really works. I've always been a fan of the idea that as long as it works, the player doesn't have to know how you did it.

Hope that helps, and if you find a way that works, let me know :P

EDIT: I'm not sure about axle friction either, but you could use setTorque(0.0f) to stop a wheel from turning at all, for example to turn left move the wheels on the right, and set all the wheels on the left to 0
Tell me what you cherish most. Give me the pleasure of taking it away.
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

Post by white tiger »

I shuold do this. When press "right", add torque to the right tires and set a soft break to the left tires (
setCalculateMaxBrakeAcceleration to true ,
setBrakeAcceleration to a small negative value and
setBrakeMaxFrictionTorque setted to a minimum non zero fixed value to apply rolling friction). The opposite with "left" key.

If it is too slow or too fast, play with tire torques and the above three functions. I don't know if that works, I don't play with :wink:
olivehehe_03
Posts: 157
Joined: Tue Mar 20, 2007 8:30 am

Post by olivehehe_03 »

That kinda works, it turns but it still turns too slow to be practical. I'm probably just gonna cheat and turn the wheels like on a normal ICar, like steering :D
Tell me what you cherish most. Give me the pleasure of taking it away.
death_au
Posts: 38
Joined: Tue Apr 17, 2007 9:48 am
Location: Australia

Post by death_au »

olivehehe_03 wrote:That kinda works, it turns but it still turns too slow to be practical. I'm probably just gonna cheat and turn the wheels like on a normal ICar, like steering :D
Yeah, I'm thinking I might do something like that, too. I've got a tank model I can apply animations to, and I can just put the "wheels" inside the tank, or even make them invisible somehow.
On that note, when I load up my tank model and attach some wheels, the wheels are always 90 degrees out. I tried rotating the wheels, but it was just the shapes that rotated, the wheels still spun sideways. And when I tried to rotate the model, the wheels rotated with it. Even if i rotated the model long before I attached any wheels.
death_au
Posts: 38
Joined: Tue Apr 17, 2007 9:48 am
Location: Australia

Post by death_au »

Just an update. I ended up just using a normal ICar object after all. I loaded up my tank mesh as the chassis node, and made four wheel objects, and for their scene nodes I called setVisible(false);
After that, the moving and steering is just a couple of if statements like this:

Code: Select all

if(right && left)
{
	car_body->forward();
	car_body->noTurn();
}
else if(left && !right)
{
	car_body->forward();
	car_body->turnRight();
}
else if(right && !left)
{
	car_body->forward();
	car_body->turnLeft();
}
else
{
	car_body->noMove();
	car_body->noTurn();
}
Also, there is another way to do it "properly", but I can't quite wrap my head around collision callbacks yet. There was a tank demo created on the newton forums which it pretty much perfect (here is the link) which has no source code :( but is based off a tutorial to make a conveyor belt in OgreNewt (here's the link to OgreNewt). The tank is basically made up of the body and two (inverted) conveyor belts. Pity there's no source for the tank demo *shakes fist*
I probably should be able to just look at the OgreNewt code and port it to IrrNewt, but I just can't wrap my head around how material callbacks work, so unless someone is able to port that tutorial to IrrNewt I'll just be sticking with the cheating car idea
Image
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

Post by white tiger »

Also, there is another way to do it "properly", but I can't quite wrap my head around collision callbacks yet.
what's the problem? just derive irr::newton::IMaterialCollisionCallback
in a your class, define the 3 callbacks, instantiate this your class and then call IMaterial::setCollisionCallback. Also the demo example use material collision callback

Also ICar is for 4 wheeled vehicle backward tired. For a tank you should use IVehicleSimple
olivehehe_03
Posts: 157
Joined: Tue Mar 20, 2007 8:30 am

Post by olivehehe_03 »

white tiger wrote:Also ICar is for 4 wheeled vehicle backward tired. For a tank you should use IVehicleSimple
That makes sense, that way you can turn all 4 wheels and have more control over the whole thing than you get from an ICar.

Doing it the way death_au said does seem like the easiest solution for getting a tank working. You'll get all the basic functionality of a tank, that is going forwards, backwards and turning with the least amount of code. If the gamer can't tell the difference and it works, go for it! :P
Tell me what you cherish most. Give me the pleasure of taking it away.
Vsk
Posts: 343
Joined: Thu Sep 27, 2007 4:43 pm

Post by Vsk »

Hi, I don't know if you continue with this proyect, but I am doing kinda a tank simulator too.
I simulating the track with 9 wheels per side. 7 wheels per side paralels and 2 on each extream wich simulte the front part of the track (it is usefull for climbing hills).

Then I have traction for each track, this is I acelerate and desacelerate the whole wheels for each track indepentily.
So for turning, I realy use the realy "way" for turning tanks. I acelerate only one track and if want turn faster I just get "reverse" at the other track at the same time.

There is something important and is that wheels must have a low mass, i don't know why, but if yyou use a "proportional" mass, then it will turn very slow or not turn at all.

I hopees it help you.
Post Reply