|
|
Re: Flying dragon move backward
[Re: Realspawn]
#455202
10/13/15 08:35
10/13/15 08:35
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
perhaps placing a certain distance between the dragon and the player pointer that allways have to be the same so it flies with player and player can never walk go past it or in this case keep turning to the player. It uses no reverse it keeps the dragon directed at the player  it still can shoot fireballs while its flying
#define idle 1
#define following 2
#define dead 3
#define status skill1
action my_enemy() // attach this action to your enemies
{
while (!hero) {wait (1);}
var idle_percentage = 0;
var run_percentage = 0;
VECTOR temp;
set (my, POLYGON); // use accurate collision detection
my.status = idle; // that's the same thing with my.skill1 = 1; (really!)
vec_set (temp.x, my.x); // trace 10,000 quants below the player
temp.z -= 10000;
my.z -= c_trace (my.x, temp.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX) - 20; // play with 20
while (my.status != dead) // this loop will run for as long as my.skill1 isn't equal to 3
{
vec_set (temp.x, my.x); // trace 10,000 quants below the player
temp.z -= 10000;
temp.z = -c_trace (my.x, temp.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX) - 20; // play with 20
if (my.status == idle) // hanging around?
{
ent_animate(my, "stand", idle_percentage, ANM_CYCLE); // play the "stand" aka idle animation
idle_percentage += 3 * time_step; // "3" controls the animation speed
if (vec_dist (hero.x, my.x) < 1000) // the player has come too close?
{
// scanned in the direction of the pan angle and detected the player?
if ((c_scan(my.x, my.pan, vector(120, 60, 1000), IGNORE_ME) > 0) && (you == hero))
{
my.status = following; // then attack the player even if it hasn't fired at the enemy yet
}
}
}
if (my.status == following) // shooting at the player?
{
vec_set(temp, hero.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan, temp); // turn the enemy towards the player
if (vec_dist (hero.x, my.x) > 100) // the distance between player and enemy is bigger than 100 quants?
{
c_move (my, vector(10 * time_step, 0, temp.z), nullvector, GLIDE); // move towards the player
ent_animate(my, "run", run_percentage, ANM_CYCLE); // play the "run" animation
run_percentage += 6 * time_step; // "6" controls the animation speed, using normal animation
}
if (vec_dist (hero.x, my.x) < 90) // the distance between player and enemy is smaller than 90 quants?
{
c_move (my, vector(-10 * time_step, 0, temp.z), nullvector, GLIDE); // move away from the player
ent_animate(my, "run", run_percentage, ANM_CYCLE); // play the "run" animation
run_percentage -= 6 * time_step; // "6" controls the animation speed, using a reversed animation
}
if (vec_dist (hero.x, my.x) > 500) // the player has moved far away from the enemy?
{
my.status = idle; // then switch to "idle"
}
}
wait (1);
}
set (my, PASSABLE); // allow the player to pass through the corpse now
}
here is a clip that shows it in action you can make it use any animation or function you want. https://youtu.be/eQzcIWnrJs0 Thank you Realspawn for your advice. I took your coding concept, and adapted it to my code. It seems to work pretty well. Thank you again.
|
|
|
Re: Flying dragon move backward
[Re: Realspawn]
#455218
10/13/15 17:15
10/13/15 17:15
|
Malice
Unregistered
|
Malice
Unregistered
|
@Wjbender "result" is internally owned. But true, you should ways check the return of the scan. Also in this case the scan is use flag2 to detect the player only, but in other cases it would trigger on any ent and set "result" and "you" to the closest ent. Returns: Distance to closest object found, or 0 if no object was found. Modifies: you -- Pointer to the closest detected entity. result -- Distance to the closest detected object. target -- Position of the closest detected object. bounce -- Direction to the closest detected camera position. tex_color -- Color of the closest detected static light. Using the internal result
result =0;
c_scan(....)
if(result)
Using a var or skill
my.skill90=0;
my.skill90=c_scan(....)
if(my.skill90)
Using all of them
my.skill90=c_scan(.....);
if(my.skill90 == result && my.skill90 != 0)
{
if(you ==t_pointer)
{
if(vec_dist(my.x, traget.x) < num_for_range)
// OR if(result < num_for_range)
{
Do actions....
|
|
|
Re: Flying dragon move backward
[Re: ]
#455224
10/13/15 17:56
10/13/15 17:56
|
Malice
Unregistered
|
Malice
Unregistered
|
In my code above I changed the scan dist, however you could use a single set dist and many trigger lengths.
var dist_backup = 200;
var dist_hover = 400;
var dist_chase = 1000;
var dist_wait = 1500;
var dist_max_scan = 2000;
my.skill90=0;
my.skill90 = c_scan(my.x,my.pan,vector(360,0,dist_max_scan), FLAGS_HERE);
if(my.skill90 && you == player)
{
if(result < 200)
my.STATE = ST_BACK_UP;
//if(result < dist_backup)
//my.STATE = ST_BACK_UP;
if(result <400 && result > 200)
my.STATE = ST_HOVER;
// if(result <dist_hover && result > dist_backup)
// my.STATE = ST_HOVER;
if(result < 1000 && result > 400)
my.STATE = ST_CHASE;
// if(result < dist_chase && result > dist_hover)
// my.STATE = ST_CHASE;
if(result < 1500 && result > 1000)
my.STATE = ST_WAITING;
// if(result < dist_wait && result > dist_chase)
// my.STATE = ST_WAITING;
}
else
{
my.STATE = ST_WAITING;
}
This way you can use one scan and not have to adjust the scan length in each and every STATE that will further reduce the STATE code blocks lines. More reduction in the STATE can be achieved by removing to "face the player - code" from 3 out of 4 STATE's and just placing it once above the c_move(..)
|
|
|
Re: Flying dragon move backward
[Re: ]
#455229
10/14/15 08:35
10/14/15 08:35
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
yes you're correct 1 scan is better that a bunch , but also think about this , your using the return value of the scan which is simply a distance , so instead of a scan with flag evaluation routines etc , 1 vec_dist which directly states the evaluated entities should be even better .
Compulsive compiler
|
|
|
Re: Flying dragon move backward
[Re: Wjbender]
#455238
10/14/15 16:20
10/14/15 16:20
|
Malice
Unregistered
|
Malice
Unregistered
|
@Wjbender - Lol, Yes you are right! that's how I would have done it, but I try hack what the poster has. c_scan should be used in triggering either the scan ent's event system or the scan target's event system. That's the only thing you can not do with just a proper pointer.
-- @Ruben, you choose RealSpawns code, however using a vec or skill for a speed value will allow to use one c_move not all those. Also again you can cut down c_trace's to a single trace also. Finally with that code already using vec_dist, then as Wjbender say's, there is no need for the c_scan at all.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|