I am making a game and I have my hero and enemy. Now I want enemy to follow hero when distance between them is 400 for example. How can I make it work. Here is what I ve got so far, but it doe not work. Objects::calcAngle(Objects* obj) - calculates angle between central points of 2 objects.
float Objects::calcAngle(Objects* obj){
float dx = obj->X - this->X;
float dy = obj->Y - this->Y;
float angle=atan(dy/dx)*180/PI;
return angle;
}
void Enemy::Attack(mainCar* car){
float angle=0;
angle=this->calcAngle(car);
if(this->Distance(car)<400){
this->attack=true;
this->heading=this->calcAngle(car)+90;
this->Vtri=abs(this->Vtri);
} else if (this->Distance(car)>400) {
this->attack=false;
}
}
Vtri is speed of movement. heading is direction in degrees.
If you can give me a link to where it is described or just tell me here, it would be great. I have 2 days to submitt my project.