enemy following a path

Posted By: Vyse220

enemy following a path - 09/05/08 09:17

I've read in the manual about the path, i've created a simple path in WED, now I really don't understand how the code work, if i want that the enemy move along the path that I have created (and assigned) how must i do the code?
Someone can please make an example?
thx
Posted By: Rasch

Re: enemy following a path - 09/05/08 09:33

I could give you a simple code smile

You create a path in WED name it for example: way1 and add this action to your enemy smile

Code:
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);
	}
}

Posted By: asd

Re: enemy following a path - 09/05/08 15:40

könntest du das für mich nochmal erklären?
Posted By: yertari

Re: enemy following a path - 09/05/08 16:05

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
Posted By: Rasch

Re: enemy following a path - 09/05/08 16:21

@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

Code:
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:

Code:
var MOVEMENT_SPEED;


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:

Code:
var dist = 0;
var LastPos[3];
var Dir[3];


Selbstverständlich kannst du sie benennen wie du möchtest.

Dann kommt die Anweisung:

Code:
path_set(my, "way1");


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.

Code:
path_spline
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

Code:
dist += 12*time_step;


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:

Code:
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.

Code:
vec_diff


gibt die Differenz aus der Position der Entity und der Variable LastPos und speichert das in Variable Dir.

mit
Code:
vec_to_angle
dreht sich die Entity zur Position der Variable Dir.

Code:
vec_set
speichert die gegenwärtige Position der Entity in die Variable LastPos

Code:
ent_animate
ist dazu da um die Rennen Animation der Entity abzuspielen.

und
Code:
MOVEMENT_SPEED
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!
Posted By: asd

Re: enemy following a path - 09/05/08 16:30

also, ich habs soweit kapiert:)
könnte ich also den gegner auf den player ausrichten lassen, und schießen?
Code:
vec_to_angle(my.pan,playervector);

und das schiessen dann über
Code:
if (c_trace(my.x,playervector, IGNORE_PASSABLE | USE_POLYGON| SCAN_TEXTURE) >= 0)
{
Schuss();
}

machen???

also als grobes beispiel
Posted By: Rasch

Re: enemy following a path - 09/05/08 20:21

Du hast es erfasst smile
Posted By: Vyse220

Re: enemy following a path - 09/05/08 20:41

Thx all for the help, the code work, but I still have some problem
Quote:
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);
}

Quote:

//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
Posted By: Rasch

Re: enemy following a path - 09/05/08 20:54

you have a enemy ship that follows a path and when it hits the player ship it get destroyed? The player also can shoot at it and destroy it?
Posted By: Vyse220

Re: enemy following a path - 09/05/08 21:19

the ship can only be destroyed by the ship bullet(skill40=99), i've used that code, but it doesn't work
Posted By: Rasch

Re: enemy following a path - 09/05/08 21:38

Maybe it works with that code. I think i would do it another way

Code:
function destroy_them
{
	if (event_type == EVENT_ENTITY) 
	{
		if (you.skill40 == 99) // a ship was hit?
		{
			score_value += 100; // get 100 points for a ship
			my.skill10 = 0;
			effect(particles_explo2, 30, my.x, nullvector);
			wait(1)
			ent_remove(me);
		}
		else
		{
			if(my.skill40 = 1)
			{
				my.skill10 = 0;
				effect(particles_explo2, 30, my.x, nullvector);
				wait(1)
				ent_remove(me);
			}
		}
	}  
}

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.ENABLE_ENTITY = on;
	my.event = destroy_them;
	
	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);
	}
}


Here´s a example of the code!

> Click Here <
Posted By: Vyse220

Re: enemy following a path - 09/15/08 20:55

tryed with that code, but it doesn't work, the bullet don't touch the enemy seems like it's passable (but passable == off)
Don't know what the problem, i'm gonna get crazy Oo
Posted By: Vyse220

Re: enemy following a path - 09/19/08 18:32

sorry the double post, but no one can help me?
i really don't know what's the problem
© 2024 lite-C Forums