Jump to content
  • Advertisement

Ols (Away)

Sign in to follow this  
  • entries
  • comments
  • views

Its fixed

Sign in to follow this  


I have now solved the biggest problem I have had since starting the programming; the errant AI car!

The car was actively moving away from the Player car, for a reason that I was struggling to fathom. After a number of forum posts and a LOT of trial-and-error coding as well as an even greater amount of paper-and-pen maths, it became apparent that the problem was due to the vector that the AI car was pointing in i.e. its direction.

Any movement was always made relative to this vector and so was causing large problems. It finally came to me, potentially in a state of mild insanity from nothing else working, that I should try to translate the vector as well as making the other car movements. Therein was my solution.

Once the idea was found, the coding was pretty simple, and the code as it currently stands is:

bool CAICar::Render(LPDIRECT3DDEVICE9 pDevice)
return false;

RECT srcRect;
srcRect.top = 0;
srcRect.left = 0;
srcRect.bottom = srcRect.top + _pTextureInfo.Height;
srcRect.right = srcRect.left + _pTextureInfo.Width;

D3DXVECTOR4 tempVec;
D3DXMATRIX mtxTranslate;
mtxTranslate._41 = _pMap->GetChangeInOffsetX();
mtxTranslate._42 = _pMap->GetChangeInOffsetY();
D3DXVec2Transform(&tempVec, &_vecDirection, &mtxTranslate);
_vecDirection.x = tempVec.x;
_vecDirection.y = tempVec.y;
D3DXVec2Normalize(&_vecDirection, &_vecDirection);

_fPosX-=(_Player.GetVelocity()*_vecDirection.x) + _pMap->GetChangeInOffsetX();
_fPosY-=(_Player.GetVelocity()*_vecDirection.y) + _pMap->GetChangeInOffsetY();

D3DXVECTOR3 vCentre(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 vPosition(_fPosX, _fPosY, 0.0f);

_pSprite->Draw(_pTexture, &srcRect, &vCentre, &vPosition, D3DCOLOR_COLORVALUE(1.0f, 1.0f, 1.0f, 1.0f));

return true;

I leave this original code here to look back-on in future days, and also to help any other poor bastard who is having similar problems!

At last, I can rest easy......until the next problem
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!