Advertisement

MONSTER MOVEMENT

Started by March 25, 2001 08:40 AM
0 comments, last by BGCJR 23 years, 10 months ago
Using glrotate and gltranslate to place and rotate the monster but how do i get the monster to turn and face the player? im thinking use the players coordinates (x,y,z) compared to monster coordinates.
Game Core
this is assuming you have a class that stores the x, y and z and made two of them, player and monster.

//find the angle the monster should be at in order to face the
//player. targangle is the target angle the monster has to face
//to face the player.

if(monster.z!=player.z){targangle = atan((player.x - monster.x) / (player.z - monster.z))/6.28*360+180;}

if (player.z < monster.z)
targangle += 180;
else if (player.z == monster.z)
{
if (player.x < monster.x)
targangle = 90;
else
targangle = 270;
}

//turn the monster to face the player
//targangledist and targangledist2 are the distances
//from the current monster angle to the target monster
//angle in both directions
//gamespeed is the speed of the game and monster.turnspeed is
//how fast the monster can turn.

if (abs(monster.angle)>targangle||(monster.angle) targangledist=abs(monster.angle-targangle);
if (targangledist>=180){targangledist=360-targangledist;}

monster.angle+=monster.turnspeed*gamespeed;

targangledist2=abs(monster.angle-targangle);
if (targangledist2>=180){targangledist2=360-targangledist2;}

if (targangledist2>targangledist){monster.angle-=monster.turnspeed*gamespeed*2;}
}

I hope this helps!

This topic is closed to new replies.

Advertisement