Its fixed

posted in Ols (Away)
Published February 08, 2005
Advertisement
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){	if(!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;	D3DXMatrixIdentity(&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->Begin(D3DXSPRITE_ALPHABLEND);	_pSprite->Draw(_pTexture, &srcRect, &vCentre, &vPosition, D3DCOLOR_COLORVALUE(1.0f, 1.0f, 1.0f, 1.0f));	_pSprite->End();	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
Previous Entry Ols - flummuxed
Next Entry Untitled
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement