1 registered members (AndrewAMD),
1,248
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Player facing which enemy
[Re: iam_ufo973]
#237288
11/19/08 14:04
11/19/08 14:04
|
Joined: Jan 2004
Posts: 3,023 The Netherlands
Helghast
Expert
|
Expert
Joined: Jan 2004
Posts: 3,023
The Netherlands
|
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 regards,
|
|
|
Re: Player facing which enemy
[Re: Helghast]
#237771
11/22/08 07:38
11/22/08 07:38
|
Joined: Jul 2008
Posts: 56
iam_ufo973
OP
Junior Member
|
OP
Junior Member
Joined: Jul 2008
Posts: 56
|
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 any idea?
|
|
|
Re: Player facing which enemy
[Re: iam_ufo973]
#237795
11/22/08 11:46
11/22/08 11:46
|
mercuryus
Unregistered
|
mercuryus
Unregistered
|
make front a global variable and check in the enemies action if front==me then you know (for each enemy if he is ment).
action player(){
...
c_scan(...)
front=you;
...
}
action enemy(){
...
// I was ment by the player
if(front==me){
.... // defend
}else{
.... // attack
}
}
mercuryus
|
|
|
Re: Player facing which enemy
[Re: iam_ufo973]
#237888
11/23/08 08:48
11/23/08 08:48
|
mercuryus
Unregistered
|
mercuryus
Unregistered
|
|
|
|
Re: Player facing which enemy
[Re: ]
#238033
11/24/08 10:00
11/24/08 10:00
|
Joined: May 2006
Posts: 53 Puerto Rico
monchito
Junior Member
|
Junior Member
Joined: May 2006
Posts: 53
Puerto Rico
|
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]
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]
|
|
|
Re: Player facing which enemy
[Re: monchito]
#238174
11/25/08 11:37
11/25/08 11:37
|
Joined: Jan 2004
Posts: 3,023 The Netherlands
Helghast
Expert
|
Expert
Joined: Jan 2004
Posts: 3,023
The Netherlands
|
just for the record, and use for other people; here's the snippet i used and PM'd to iam_ufo...
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: 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 regards,
|
|
|
|