Player facing which enemy

Posted By: iam_ufo973

Player facing which enemy - 11/19/08 14:00

HI friends i have a very complicated problem please solve it.
if enemies have surrounded the player how do they know that the player is facing & fighting to which one of them? so they take decision to fight or defend.
Posted By: Helghast

Re: Player facing which enemy - 11/19/08 14:04

if i get home, and dont forget about it, i have a small piece of code, that checks a cone in front of a model.
send me a PM, i'll keep reminded that way wink

regards,
Posted By: iam_ufo973

Re: Player facing which enemy - 11/22/08 07:38

In player's action i put this code.

if ((c_scan(my.x, my.pan, vector(45, 60, 60), ignore_me) > 0))
{
if(you.skill51!=yes)
{
you.skill51 = yes;
front=you; //front is an entity pointer
}
}

It successfully assign the front pointer to the scanned entity and turn it's skill51 on but it doesn't turn it back off when player is not facing him anymore frown any idea?
Posted By: Anonymous

Re: Player facing which enemy - 11/22/08 11:46

make front a global variable and check in the enemies action if front==me then you know (for each enemy if he is ment).

Code:
action player(){
   ...
   c_scan(...)
   front=you;
   ...
}

action enemy(){
   ...
   // I was ment by the player
   if(front==me){
     ....  // defend
   }else{
     ....  // attack
   }
}

mercuryus
Posted By: iam_ufo973

Re: Player facing which enemy - 11/22/08 13:14

doesn't work tired
Posted By: iam_ufo973

Re: Player facing which enemy - 11/22/08 14:42

Someone please help me how to know that player is facing which enemy?
Posted By: Vonman

Re: Player facing which enemy - 11/22/08 15:33

I suppose you use a C-Scan to detect the enemies, assign a pointer to the two closest enemies, face the player toward the first closest, then when that enemy is dead aim at the second, then use c-scan again and start over.
Posted By: Anonymous

Re: Player facing which enemy - 11/23/08 08:48

here is the coding for different methods (attracting one or many)

mercuryus
Posted By: monchito

Re: Player facing which enemy - 11/24/08 10:00

Hi:
Try this code maybe can help you. Set the skill51 when player is looking at the target enemy, otherwise reset skill51 to 0;
It's a simple solution, a more elaborate one must be done.
Code:
[/code]
function act_player();
function act_enemy();

entity* front;

font standard_font = "c:/windows/fonts/arial", 1, 22;

PANEL PanData   // show data on screen
{
  layer = 5;
  digits = 0,450,"Data:%3.0f",standard_font,1,front.skill51;
  flags = TRANSLUCENT,VISIBLE;
}

function main()
{
   fps_max = 50;
   level_load (NULL);
   wait(5);
// load the (player entity, assign position, and default function) 
   ent_create ("player.mdl", vector(40,0,0), act_player);   
   ent_create ("enemy.mdl", vector(100,0,0), act_enemy);   
   ent_create ("enemy.mdl", vector(100,50,0), act_enemy); 
   ent_create ("enemy.mdl", vector(100,-50,0), act_enemy);   
}

function act_player()
{
  var speed = 5;
  var rotation_speed = 3;
  my.scale_x = .5; 
  my.scale_y = .5;
  my.scale_z = .5;
  my.passable = on;
  player = my;
	
  while(1)      
  {
     move_mode = IGNORE_PASSABLE + USE_BOX;  
      
     if(key_w == 1)
     { 
        // perform movement
        c_move (my,vector(speed * time_step,0,0), nullvector, move_mode);
     }
     
     if(key_s == 1)
     {
       c_move (my,vector(-speed * time_step,0,0), nullvector,move_mode);
     }
     // perform rotation
     if(key_a == 1) { my.pan += rotation_speed * time_step; };
     if(key_d == 1) { my.pan -= rotation_speed * time_step; };
     if(key_q == 1) { my.tilt += 1; }
     if(key_z == 1) { my.tilt -= 1; }
    
     // set/reset skill51
     if ((c_scan(my.x, my.pan, vector(45, 60, 60), ignore_me) > 0))     
     {
       you.skill51 = 1;
       front = you;
     }
     else
     {
      	if(front)
        { 
          front.skill51 = 0;
        }
     }  
     wait(1);
  }
}

function act_enemy()
{
  var percent;
  
  my.scale_x = .5; 
  my.scale_y = .5;
  my.scale_z = .5;
	
  while(1) // see me moonwalk if skill51 active (player looking at me)     
  {
     if(my.skill51 == 1) 
     {
       percent += 3 * time_step;
       ent_animate(my,"walk", percent, ANM_CYCLE);
       percent %= 100;
     }
     wait(1);
  }
}
[code]

Posted By: Helghast

Re: Player facing which enemy - 11/25/08 11:37

just for the record, and use for other people;

here's the snippet i used and PM'd to iam_ufo...

Code:
if(plane)
{
	vec_set(temp.x, plane.x); 
	vec_sub(temp.x, my.x);
	vec_to_angle(movedirection.pan, temp.x);
	my.pan+=ang(movedirection.pan-my.pan)/110;
	my.tilt+=ang(movedirection.tilt-my.tilt)/110;
			
	if(vec_dist(plane.x, my.x) < 5000 && abs(ang(movedirection.pan-my.pan)) < 30)
	{
		if(bullet_down <= 0){ ent_playsound(my, bullet_fire, 1000); enemy_bullet_shoot(); bullet_down = 10; }
		bullet_down -= 1;
	}
}


actual check if its in view is in this piece of code:
Code:
 abs(ang(movedirection.pan-my.pan)) < 30 


however, this is still done in A6, might have to be converted to A7... i dunno, lol :P

anyway, have fun with this one wink

regards,
© 2024 lite-C Forums