User:Frozenrain        

I am testing this and may mess up so i apologize if you see then when you don't intend to.

This section is copied from "how to drive a car" page, just added ai page because I will be adding more for ai later.

Problem



You have a car and you have a point (i.e. waypoint), but you don't know how to determine to which side the car should turn to drive to the point (left or right).

Solution

Your first thought might be that solving this requires some math. But we like neither math nor magical formulas. Luckily, there is a clean, easy and simple solution. Just look at the picture:

HowToDriveCar.jpg

Left Node and Right Node are children of the car node, placed on the same distance at the left and right of the car. I.e. if the car is initially oriented along (0,0,1), left node would be (-1,0,0) and right one (1,0,0). What is the solution? Just take side which node is closer to the waypoint. No math formulas!

This section is the very basic initialization of nodes on all sides. We have added an object to them so we can physicly see them to test it.

//Creating Left node for AI

    mSceneMgr->getSceneNode("Car1")->createChildSceneNode("TestNodeLeft",Ogre::Vector3(0,0,2));

    Entity* ent;

    ent = mSceneMgr->createEntity("TestLeft","mine.mesh");

    mSceneMgr->getSceneNode("TestNodeLeft")->setScale(0.01,0.01,0.01);

    mSceneMgr->getSceneNode("TestNodeLeft")->attachObject(ent);

    //Creating Right Node for AI
    mSceneMgr->getSceneNode("Car1")->createChildSceneNode("TestNodeRight",Ogre::Vector3(0,0,-2));

    ent = mSceneMgr->createEntity("TestRight","mine.mesh");

    mSceneMgr->getSceneNode("TestNodeRight")->setScale(0.01,0.01,0.01);

    mSceneMgr->getSceneNode("TestNodeRight")->attachObject(ent);

    //Creating Front Node for AI
    mSceneMgr->getSceneNode("Car1")->createChildSceneNode("TestNodeFront",Ogre::Vector3(-3,0,0));

    ent = mSceneMgr->createEntity("TestFront","mine.mesh");

    mSceneMgr->getSceneNode("TestNodeFront")->setScale(0.01,0.01,0.01);

    mSceneMgr->getSceneNode("TestNodeFront")->attachObject(ent);

    //Creating Back node for AI
    mSceneMgr->getSceneNode("Car1")->createChildSceneNode("TestNodeBack",Ogre::Vector3(2,0,0));

    ent = mSceneMgr->createEntity("TestBack","mine.mesh");

    mSceneMgr->getSceneNode("TestNodeBack")->setScale(0.01,0.01,0.01);

    mSceneMgr->getSceneNode("TestNodeBack")->attachObject(ent); 

I will be adding more later as I figure out ai for avoidig collisions, attacking an apponent and other things.