Hi...
I am experimenting with creation of a car game.
I have 6 nodes....
garage
carbody
wheel1
wheel2
wheel3
wheel4
I want to move the car and its wheels in to the garage while making the 4 wheels turn as the car moves in to the garage,
I have managed to get the car and the wheels move into the garage using 5 x smgr->createFlyStraightAnimator
But I have not been able to make the wheels turn while the car is moving.
I have been thinking abut having a sub rutine called DriveIntoGarage that creates the whole animation step by step by using a timer of sorts... But I havent been successfull so far... Any advice and/or preferably code samples ?
I found several car example games for irrlicht with source but I haven't been able to make them both compile and run
My own project however does run and compile on my pc.
I am using visual c++ 2008 express edition and irrlicht v.1.8.1
I have also added the newton and tinyxml libs to my game
creating a car game
Re: creating a car game
You have 2 ways to rotate wheels. One is that you code it yourself - you have to figure out how to rotate objects around an axis and call that each frame. The other is to export the wheel already with a rotation animation from a 3d modeling tool and then play that animation in the speed you want.
The other part - moving a car along a certain path is actually a little bit tricky. I wouldn't use any Irrlicht animator but write my own. And it would do 2 things. The first is that the object would follow a bezier curve (you'll find implementations for those a lot on the net). That allows you to move objects along all kind of paths by defining 3-4 points. If you draw curves in painting tools those often use bezier curves. The second part is that the direction of the node should always look along the path. Which means basically it takes a point further along the path and rotates until it looks there.
Thought that all is only about doing a fixed animation. I guess in a game you rather want to drive the car yourself instead of moving it? That works very different - cutscenes and game-controls are programmed on their own.
The other part - moving a car along a certain path is actually a little bit tricky. I wouldn't use any Irrlicht animator but write my own. And it would do 2 things. The first is that the object would follow a bezier curve (you'll find implementations for those a lot on the net). That allows you to move objects along all kind of paths by defining 3-4 points. If you draw curves in painting tools those often use bezier curves. The second part is that the direction of the node should always look along the path. Which means basically it takes a point further along the path and rotates until it looks there.
Thought that all is only about doing a fixed animation. I guess in a game you rather want to drive the car yourself instead of moving it? That works very different - cutscenes and game-controls are programmed on their own.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: creating a car game
Thanks for the reply.
I figured out how to use the Irrlicht timer stuff
I used this in an earlier attempt... it worked fine but it messed around the irrlicht timer function somehow? So I was not able to add turning to the wheels (rims+tires)
smgr->createFlyStraightAnimator(core::vector3df(6.2, -2.4, -36.,
core::vector3df(6.2, -2.4, 5.2), 5500, false);
my current code moves the car manually, and it does work.... I still have 2 problems...
1. the wheels do not "turn" correctly when manipulating either the X, Y or Z axis
2. the animation/timer function becomes "erradic" if I use a dely larger than 100 ms, I would expect the movement to be choppy if the delay was 1 second,
but I would still expect it to run once each and every second untill done. It might be my placement of the animation code?
I have giving it some though in regards to writing my own animator along the lines of the "createFlyStraightAnimator".But I havent found any good code examples to look at.
a bezier curve? I must look in to that
I WILL eventually have some driving animation and simulation in the game, but the best place to begin for this particular game is the garage scene
I also have TinyXML (for setup files, I have some experience in using this library) and
Newton (for better physics than Bullet?) added to my car game project.
Here is a code snippet...
int GameTimer = 0;
bool StartAnimationNotDone = TRUE;
int movement = 0;
int xoffset = 0;
int yoffset = 0;
int zoffset = 0;
int bodypos = -30;
int frontwheelpos = -22.5;
int rearwheelpos = -36.8;
vector3df wheel1rotation = nodewheel1->getRotation();
vector3df wheel2rotation = nodewheel2->getRotation();
vector3df wheel3rotation = nodewheel3->getRotation();
vector3df wheel4rotation = nodewheel4->getRotation();
while(device->run())
{
GameTimer = device->getTimer()->getTime();
if ( StartAnimationNotDone == TRUE )
{
if (movement > 42)
{
StartAnimationNotDone = FALSE;
//cout << "TICK DONE! ";
}
if ( ( GameTimer % 10 ) == 0 )
{
movement = movement + 1;
nodecar->setPosition(vector3df(10, -0.9, bodypos+movement)); // 12 position -30 to 12 total is 42
nodewheel1->setPosition(vector3df(13.8, -2.4, frontwheelpos+movement)); // 19.5 position -22.5 to 19.5 total is 42
nodewheel2->setPosition(vector3df(6.2, -2.4, frontwheelpos+movement)); // 19.5 position -22.5 to 19.5 total is 42
nodewheel3->setPosition(vector3df(13.8, -2.4, rearwheelpos+movement)); // 5.2 position -36.8 to 5.2 total is 42
nodewheel4->setPosition(vector3df(6.2, -2.4, rearwheelpos+movement)); // 5.2 position -36.8 to 5.2 total is 42
xoffset = movement*20;
yoffset = 0;
zoffset = 0;
nodewheel1->setRotation(vector3df( wheel1rotation.X + xoffset, wheel1rotation.Y + yoffset, wheel1rotation.Z + zoffset));
nodewheel2->setRotation(vector3df( wheel2rotation.X + xoffset, wheel2rotation.Y + yoffset, wheel2rotation.Z + zoffset));
nodewheel3->setRotation(vector3df( wheel3rotation.X + xoffset, wheel3rotation.Y + yoffset, wheel3rotation.Z + zoffset));
nodewheel4->setRotation(vector3df( wheel4rotation.X + xoffset, wheel4rotation.Y + yoffset, wheel4rotation.Z + zoffset));
}
}
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(255,200,200,200));
smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Streetrod 3 Project Phoenix Quick Test [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
else
device->yield();
}
/*
In the end, delete the Irrlicht device.
*/
device->drop();
return 0;
}
I figured out how to use the Irrlicht timer stuff
I used this in an earlier attempt... it worked fine but it messed around the irrlicht timer function somehow? So I was not able to add turning to the wheels (rims+tires)
smgr->createFlyStraightAnimator(core::vector3df(6.2, -2.4, -36.,
core::vector3df(6.2, -2.4, 5.2), 5500, false);
my current code moves the car manually, and it does work.... I still have 2 problems...
1. the wheels do not "turn" correctly when manipulating either the X, Y or Z axis
2. the animation/timer function becomes "erradic" if I use a dely larger than 100 ms, I would expect the movement to be choppy if the delay was 1 second,
but I would still expect it to run once each and every second untill done. It might be my placement of the animation code?
I have giving it some though in regards to writing my own animator along the lines of the "createFlyStraightAnimator".But I havent found any good code examples to look at.
a bezier curve? I must look in to that
I WILL eventually have some driving animation and simulation in the game, but the best place to begin for this particular game is the garage scene
I also have TinyXML (for setup files, I have some experience in using this library) and
Newton (for better physics than Bullet?) added to my car game project.
Here is a code snippet...
int GameTimer = 0;
bool StartAnimationNotDone = TRUE;
int movement = 0;
int xoffset = 0;
int yoffset = 0;
int zoffset = 0;
int bodypos = -30;
int frontwheelpos = -22.5;
int rearwheelpos = -36.8;
vector3df wheel1rotation = nodewheel1->getRotation();
vector3df wheel2rotation = nodewheel2->getRotation();
vector3df wheel3rotation = nodewheel3->getRotation();
vector3df wheel4rotation = nodewheel4->getRotation();
while(device->run())
{
GameTimer = device->getTimer()->getTime();
if ( StartAnimationNotDone == TRUE )
{
if (movement > 42)
{
StartAnimationNotDone = FALSE;
//cout << "TICK DONE! ";
}
if ( ( GameTimer % 10 ) == 0 )
{
movement = movement + 1;
nodecar->setPosition(vector3df(10, -0.9, bodypos+movement)); // 12 position -30 to 12 total is 42
nodewheel1->setPosition(vector3df(13.8, -2.4, frontwheelpos+movement)); // 19.5 position -22.5 to 19.5 total is 42
nodewheel2->setPosition(vector3df(6.2, -2.4, frontwheelpos+movement)); // 19.5 position -22.5 to 19.5 total is 42
nodewheel3->setPosition(vector3df(13.8, -2.4, rearwheelpos+movement)); // 5.2 position -36.8 to 5.2 total is 42
nodewheel4->setPosition(vector3df(6.2, -2.4, rearwheelpos+movement)); // 5.2 position -36.8 to 5.2 total is 42
xoffset = movement*20;
yoffset = 0;
zoffset = 0;
nodewheel1->setRotation(vector3df( wheel1rotation.X + xoffset, wheel1rotation.Y + yoffset, wheel1rotation.Z + zoffset));
nodewheel2->setRotation(vector3df( wheel2rotation.X + xoffset, wheel2rotation.Y + yoffset, wheel2rotation.Z + zoffset));
nodewheel3->setRotation(vector3df( wheel3rotation.X + xoffset, wheel3rotation.Y + yoffset, wheel3rotation.Z + zoffset));
nodewheel4->setRotation(vector3df( wheel4rotation.X + xoffset, wheel4rotation.Y + yoffset, wheel4rotation.Z + zoffset));
}
}
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(255,200,200,200));
smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Streetrod 3 Project Phoenix Quick Test [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
else
device->yield();
}
/*
In the end, delete the Irrlicht device.
*/
device->drop();
return 0;
}
Re: creating a car game
The questions are all over the place... I'm not sure how to even start explaining.
For real racer-sources, check supertuxkart: https://sourceforge.net/p/supertuxkart/ ... trunk/src/
Especially take a look at their main-loop: https://sourceforge.net/p/supertuxkart/ ... n_loop.cpp
You will notice they do basically only the very high-level stuff in there.
Certainly that project does far more than you need for a little racer, but even a simple racer is not exactly the easiest project to start with.
My recommendation would be - start with a simpler game. Something like Pong or Space Invaders. It's easier to get familiar with game programming with simple games first before you start a complex project like a racer with cut-scenes. Do a little project but think about how to do it well. How to avoid code-repetition, how to put stuff into classes and functions. This also allows you to get a little more familiar with the engine first. And then add stuff like high-scores which are saved, config settings which are loaded from file and so on. That way you get familiar with how to configurate stuff from file instead of hard-coding it. If you do a space-invader you can for example experiment with simple movement and rotations (let the enemies rotate before they shoot for example).
It's really hard if you are still relatively new to programming to do a full 3D game. Then you have to learn it all at the same time and it will all seem crazy difficult ... and others have a hard time helping you because your qustions are not yet specific enough to make them easy to answer.
And some hints for posting here. We have code tags which make reading code easier. Also you can put larger sources at http://ideone.com/ and link to those. At this point you shouldn't be worried yet about anyone stealing your sources, so don't hesitate to just post your whole files there. And then in your questions maybe ask about problems in specific lines. It will make it easier for others to help you out.
For real racer-sources, check supertuxkart: https://sourceforge.net/p/supertuxkart/ ... trunk/src/
Especially take a look at their main-loop: https://sourceforge.net/p/supertuxkart/ ... n_loop.cpp
You will notice they do basically only the very high-level stuff in there.
Certainly that project does far more than you need for a little racer, but even a simple racer is not exactly the easiest project to start with.
My recommendation would be - start with a simpler game. Something like Pong or Space Invaders. It's easier to get familiar with game programming with simple games first before you start a complex project like a racer with cut-scenes. Do a little project but think about how to do it well. How to avoid code-repetition, how to put stuff into classes and functions. This also allows you to get a little more familiar with the engine first. And then add stuff like high-scores which are saved, config settings which are loaded from file and so on. That way you get familiar with how to configurate stuff from file instead of hard-coding it. If you do a space-invader you can for example experiment with simple movement and rotations (let the enemies rotate before they shoot for example).
It's really hard if you are still relatively new to programming to do a full 3D game. Then you have to learn it all at the same time and it will all seem crazy difficult ... and others have a hard time helping you because your qustions are not yet specific enough to make them easy to answer.
And some hints for posting here. We have code tags which make reading code easier. Also you can put larger sources at http://ideone.com/ and link to those. At this point you shouldn't be worried yet about anyone stealing your sources, so don't hesitate to just post your whole files there. And then in your questions maybe ask about problems in specific lines. It will make it easier for others to help you out.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: creating a car game
I have experience with simpler games in 2d in other languages both procedural and object oriented.
I know a racing game in c++ should be object oriented and it will be. But right now I just wanted to test out some stuff in the engine. I should have used the correct tags to post the code in order to ref line numbers.
I am not worried about posting code since the project is open source.
My biggest problems with this particular project are...
1) I am not experienced in c++
2) I have not yet coded a complete 3d game
3) I have never made any car related games
4) I am very rusty in regards to coding atm
but I guess I could try a simpler project in 3D to learn more about 3d games.
I will however not abandon this project completely to do that.
This community project needs to be done and I am the only one coding for it atm.
But I see it as a welcome opportunity for me to learn new things
Thanks for all the help so far. I will study your advices
I know a racing game in c++ should be object oriented and it will be. But right now I just wanted to test out some stuff in the engine. I should have used the correct tags to post the code in order to ref line numbers.
I am not worried about posting code since the project is open source.
My biggest problems with this particular project are...
1) I am not experienced in c++
2) I have not yet coded a complete 3d game
3) I have never made any car related games
4) I am very rusty in regards to coding atm
but I guess I could try a simpler project in 3D to learn more about 3d games.
I will however not abandon this project completely to do that.
This community project needs to be done and I am the only one coding for it atm.
But I see it as a welcome opportunity for me to learn new things
Thanks for all the help so far. I will study your advices