irrNewt - moving a tank
irrNewt - moving a tank
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?
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?
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.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'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.
-
- Posts: 157
- Joined: Tue Mar 20, 2007 8:30 am
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
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
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
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
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.
-
- Posts: 269
- Joined: Tue Oct 31, 2006 3:24 pm
- Contact:
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
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
-
- Posts: 157
- Joined: Tue Mar 20, 2007 8:30 am
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.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
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.
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:
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
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();
}
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
-
- Posts: 269
- Joined: Tue Oct 31, 2006 3:24 pm
- Contact:
what's the problem? just derive irr::newton::IMaterialCollisionCallbackAlso, there is another way to do it "properly", but I can't quite wrap my head around collision callbacks yet.
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
-
- Posts: 157
- Joined: Tue Mar 20, 2007 8:30 am
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.white tiger wrote:Also ICar is for 4 wheeled vehicle backward tired. For a tank you should use IVehicleSimple
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!
Tell me what you cherish most. Give me the pleasure of taking it away.
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.
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.