1 registered members (AndrewAMD),
1,268
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: enemy following a path
[Re: Vyse220]
#225606
09/05/08 09:33
09/05/08 09:33
|
Joined: Jun 2008
Posts: 428
Rasch
Senior Member
|
Senior Member
Joined: Jun 2008
Posts: 428
|
I could give you a simple code You create a path in WED name it for example: way1 and add this action to your enemy define MOVEMENT_SPEED, skill1;
action enemy_follow_path
{
var dist = 0; // entity walk speed
var LastPos[3];
var Dir[3];
path_set(my, "way1"); // Change way1 to the name of your path set in WED
while(1)
{
path_spline(me,my.x,dist); // spline curve for smooth walking
dist += 12*time_step; // change this to change the walk speed
c_move(me,vector(1*time_step,0,0),nullvector,IGNORE_YOU); // this is for collision but you don´t need
vec_diff(Dir,my.x,LastPos);
vec_to_angle(my.pan,Dir);
vec_set(LastPos,my.x);*/
ent_animate(my, "run", my.MOVEMENT_SPEED, ANM_CYCLE);
my.MOVEMENT_SPEED += 10 * time_step;
wait(1);
}
}
|
|
|
Re: enemy following a path
[Re: asd]
#225658
09/05/08 16:05
09/05/08 16:05
|
Joined: Sep 2005
Posts: 392
yertari
Senior Member
|
Senior Member
Joined: Sep 2005
Posts: 392
|
In the above example, am i right in saying 'my' is the name you have used in your code to indicate the character following the waypoint? So if the character was a wizard, i would change my with wizard?
What about the 'me' variable.
Also if the character was near the player, what kind of code would then the character to stop foillowing the path and attack
Thanks
Steve
Arteria3d - Providers of quality 3d assets and game audio
|
|
|
Re: enemy following a path
[Re: asd]
#225663
09/05/08 16:21
09/05/08 16:21
|
Joined: Jun 2008
Posts: 428
Rasch
Senior Member
|
Senior Member
Joined: Jun 2008
Posts: 428
|
@yertari no! my is the entity who was given the action enemy_follow_path. me and my is the same. you could replace it with my. Vyse asked for a path code. Thats somehting else. But for example you could do a c_scan or c_trace. As long as the scan don´t hit a entity it follows the path else it is attacking define MOVEMENT_SPEED, skill1;
action enemy_follow_path
{
var dist = 0; // entity walk speed
var LastPos[3];
var Dir[3];
var look_around;
path_set(my, "way1"); // Change way1 to the name of your path set in WED
while(1)
{
vec_set(look_around.x, vector(10000, 0, 0));
vec_rotate(look_around.x, camera.pan);
vec_add(look_around.x, camera.x);
c_trace(my.x, look_around.x, IGNORE_ME | IGNORE_PASSABLE | USE_POLYGON);
if(you == 1)
{
// attack code
}
else
{
path_spline(me,my.x,dist); // spline curve for smooth walking
dist += 12*time_step; // change this to change the walk speed
c_move(me,vector(1*time_step,0,0),nullvector,IGNORE_YOU); // this is for collision but you don´t need
vec_diff(Dir,my.x,LastPos);
vec_to_angle(my.pan,Dir);
vec_set(LastPos,my.x);*/
ent_animate(my, "run", my.MOVEMENT_SPEED, ANM_CYCLE);
my.MOVEMENT_SPEED += 10 * time_step;
}
wait(1);
}
} @asd Also zuerst lege ich soetwas wie eine Variable an. Eine Definition. Diese verweise ich auf Skill1. Theoretisch kannst du das ganze auch so sehen bzw. machen: Dannach schreibe ich die Action für die Entity welche ich dann auch dem Model in WED zuweise bzw per ent_create. Nun werden INTERNE Variablen für die Action angelegt. DAs wären: var dist = 0;
var LastPos[3];
var Dir[3]; Selbstverständlich kannst du sie benennen wie du möchtest. Dann kommt die Anweisung: was soviel heist wie lege für mich die Route/Weg mit dem Namen "way1" fest. Hast du also im WED einen Pfad kreiert und ihn way1 genannt wird die Entity sich sozusagen auf diesem Pfad nun entlang bewegen. Nun kommt ein Befehlt den ich auch heute selber noch nicht ganz verstehe. soll laut Handbuch eine weiche Kurve an den jeweiligen Punnkten berechnen sodass die Bewegung gesmooth und nicht abgehackt wirkt. Allerdings bewegt dieser Befehl die Entity auch entlang des Splines. Und das ist es was ich nicht verstehe. Jedenfalls erhöht sich mit dem Befehl die dist Variable die ja auch im path_spline drin steht, ergo bewegt sich die Figur. Da ich gerade an einem Capture the Flag Spiel arbeite und testweise meine Figuren durch die Flagge laufen lasse, sodass sie diese aufnehmen musste ich feststellen das durch das alleinige bewegen durch path_spline keine Kollision zustande kam. also habe ich den Befehl: c_move(me,vector(1*time_step,0,0),nullvector,IGNORE_YOU); eingefügt wodurch dann eine Kollision zustande kam da c_move ja eine Kollisionsabfrage macht. gibt die Differenz aus der Position der Entity und der Variable LastPos und speichert das in Variable Dir. mit dreht sich die Entity zur Position der Variable Dir. speichert die gegenwärtige Position der Entity in die Variable LastPos ist dazu da um die Rennen Animation der Entity abzuspielen. und letzendlich ist dazu da um die Animation auch voranzutreiben. Ich verstehe den Code größtenteils. Allerdings bin ich mir bei ein paar Sachen noch unklar!
|
|
|
Re: enemy following a path
[Re: Rasch]
#225665
09/05/08 16:30
09/05/08 16:30
|
Joined: Aug 2008
Posts: 55
asd
Junior Member
|
Junior Member
Joined: Aug 2008
Posts: 55
|
also, ich habs soweit kapiert:) könnte ich also den gegner auf den player ausrichten lassen, und schießen? vec_to_angle(my.pan,playervector); und das schiessen dann über if (c_trace(my.x,playervector, IGNORE_PASSABLE | USE_POLYGON| SCAN_TEXTURE) >= 0)
{
Schuss();
} machen??? also als grobes beispiel
Last edited by asd; 09/05/08 16:30.
|
|
|
Re: enemy following a path
[Re: asd]
#225720
09/05/08 20:41
09/05/08 20:41
|
Joined: Aug 2008
Posts: 49
Vyse220
OP
Newbie
|
OP
Newbie
Joined: Aug 2008
Posts: 49
|
Thx all for the help, the code work, but I still have some problem action enemy_follow_path { var dist = 0; // entity walk speed var LastPos[3]; var Dir[3]; while (player == null) {wait (1);} my.z = player.z; my.event = destroy_them; my.passable = off; my.skill40 = 1; my.skill10 = 1; path_set(my, "path_002"); //he name of your path set in WED while(my.skill10 == 1) { path_spline(me,my.x,dist); // spline curve for smooth walking dist += 12*time_step; // change this to change the walk speed c_move(me,vector(1*time_step,0,0),nullvector,IGNORE_YOU); // this is for collision but you don´t need vec_diff(Dir,my.x,LastPos); vec_to_angle(my.pan,Dir); vec_set(LastPos,my.x); my.MOVEMENT_SPEED += 10 * time_step; wait(1); } ent_remove(me); } //part of the destroy_them function if (my.skill40 == 1) // a ship was hit? { my.skill10 = 0; if (you.skill40 == 99) // if it was player's bullet { score_value += 100; // get 100 points for a ship } effect(particles_explo2, 30, my.x, nullvector); }
I've modified the code for make it be destroyed by the bullets of the player, but the enemy simple doesn't get demage, skill10 still remain 1 cause it continue to move
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|