Path makes NPC disappear

Posted By: Ruben

Path makes NPC disappear - 10/28/15 05:41

I am trying to make a model walk a certain path titled "path_001" on a spiral staircase in a WED file. I created the path in WED, and it is titled "path_001".

I placed a model on the spiral staircase. The model gets placed when I put this code in my program:

Code:
...

ENTITY* monster;

...

monster = ent_create("monster.mdl", vector(1,564,247), monster_action ); 

...



However, when I place this code in the monster_action() function:

Code:
...

action monster_code()
{
   ...

   ent_movepath(me, "path_001", 2, 1+2); // THIS CODE HERE

   while(1)
   {

      ...

      wait(1);
   }
}



...the monster that would normally have been placed when the level loaded, does not show up when the game loads.

Has anyone else had the problem of a model not being loaded when you try to program it to move along a certain path using the ent_movepath() function?
Posted By: Anonymous

Re: Path makes NPC disappear - 10/28/15 06:01

Never had the issue, however use my own path code not this function.

Simple debugging
Code:
action monster_code()
{
var I_live=0;
   ...
   if(my)
   beep();
   ent_movepath(me, "path_001", 2, 1+2); // THIS CODE HERE
   
   while(1)
   {
if(my)
I_live=1;
     DEBUG_VAR(my.x,50);
     DEBUG_VAR(my.y,100);
     DEBUG_VAR(my.z,150);
     DEBUG_VAR(I_live,200);
      ...

      wait(1);
   }
}



If you see red numbers and any are none zero, the ent was created, most likely the path name is wrong. Also listen for the BEEP - if you hear the BEEP but do not get the numbers , then ent has slipped into a black hole and become uncreated.

EDIT - also not in the ent_create action named monster_action, but action named monster_code..

EDIT2- ACTUAL code for ent_movepath - no way to REMOVE ent
Code:
// let an entity move along a closed path with given speed
function ent_movepath(ENTITY* ent,char* pathname,var speed,var mode)
{
	proc_kill2(ent_movepath,ent);
	var vLastPos[3],vDir[3];
	vec_set(vLastPos,ent.x);
	var dist = 0;
	if(pathname) path_set(ent,pathname);
	while(speed) 
	{
// place the entity along the path
		path_spline(ent,ent.x,dist);
		dist += speed*time_step;
// adjust the entity to the floor
		if(mode&1)
			ent_placefloor(ent);
// let the entity look ahead in movement direction
		if(mode&2) {
			vec_diff(vDir,ent.x,vLastPos);
			vec_to_angle(ent.pan,vDir);
			vec_set(vLastPos,ent.x);
		}
		var ehandle = handle(ent);
		wait(1);
		ent = ptr_for_handle(ehandle);
	}
}



You can edit it to debug if path is found, by changing here
Code:
var is_path=0;
if(pathname) is_path=path_set(ent,pathname);
	while(speed) 
	{ DEBUG_VAR(is_path,300);



If red '1' at pixel 300 path found, if red '0' path not found.

OK bed time for me
Have fun
Mal
Posted By: Ruben

Re: Path makes NPC disappear - 10/28/15 06:19

Originally Posted By: Malice
Never had the issue, however use my own path code not this function.

Simple debugging
Code:
action monster_code()
{
var I_live=0;
   ...
   if(my)
   beep();
   ent_movepath(me, "path_001", 2, 1+2); // THIS CODE HERE
   
   while(1)
   {
if(my)
I_live=1;
     DEBUG_VAR(my.x,50);
     DEBUG_VAR(my.y,100);
     DEBUG_VAR(my.z,150);
     DEBUG_VAR(I_live,200);
      ...

      wait(1);
   }
}



If you see red numbers and any are none zero, the ent was created, most likely the path name is wrong. Also listen for the BEEP - if you hear the BEEP but do not get the numbers , then ent has slipped into a black hole and become uncreated.


Thank you Malice.

Strange. The beep sounded. The x and y red numbers are both increasing rapidly, while the z red number stays at the same number. It seems that for some reason, the monster is being moved continuously with the x and y coordinates.

Also, the number 1 in red showed up underneath the top three values, showing that the monster entity was created.

When I comment out the ent_movepath() code in the monster_code() function, the entity loads in the spot where I put it, and the red numbers are above 0, and not changing.

So, it appears that the ent_movepath() function is somehow causing the entity to move continuously with the x and y coordinates.

I set the path along the spiral staircase in a tower, although I noticed that the yellow lines representing the path showed up on top of the tower, instead of inside the tower. I am not sure if that has anything to do with the error.
Posted By: Anonymous

Re: Path makes NPC disappear - 10/28/15 06:40

Really tired now.

Your path should not be on top of the tower. In wed select whole path -> enter vertex mode -> manually select each node and move it into place.

Also place a camera on the monsters back .. vec_set(vec_temp,vector(-150,0,0));
vec_rotate(vec_temp,my.pan);
vec_add(vec_temp,my.x);
... maybe vec_to_angle(camera.pan,vec_diff(NULL,my.x,camera.x));

See what he is up to, maybe he has a second family with a hotter, younger wife.

Ok night
Posted By: Ruben

Re: Path makes NPC disappear - 10/28/15 07:11

lol

I placed the path directly above where the spiral staircase path is, however the yellow lines and nodes representing the path appears to be located over the top of the tower that the spiral staircase is in, even though the path is in line with the spiral staircase. I thought the path applies to all locations over or under it on the z coordinate, when you create the path in WED.

In creating the path, I opened the WED file, went to Object tab / Add Path / placed the first path node along the spiral staircase / Vertex Move / then clicked on the subsequent node locations in the path along the spiral staircase.

I never thought the height on where the nodes and line were located mattered.
Posted By: Ruben

Re: Path makes NPC disappear - 10/28/15 07:22

Ah, never mind. I relocated the path lower within the tower, approximately where the monster is located. Now I see the monster, and it is moving along the spiral staircase.
Posted By: Ruben

Re: Path makes NPC disappear - 10/29/15 21:46

Okay, so what I am really trying to do is make a monster stand idle on a spiral staircase. If the player gets within a certain distance of the monster, I want the monster to stop standing idle, and follow a path titled "path_000" that I set along the entire spiral staircase from bottom to top.

So far, the monster shows up standing idle on the spiral staircase when the level is loaded. When the player gets within the certain distance of it, triggering the c_scan() function within the monster_code() function, I get this pop-up error stating:

Code:
Error E1513
Script crash in ent_movepath:
OK            Cancel



When I press the OK button, the player just moves forward on its own infinitely without me moving it, until I press the Esc button ending the game.

This is the code I have that is making this happen:

Code:
action monster_code()
{
   ...

   while(1)
   {
      ...

      my.ANIMATION += 3*time_step;	
      ent_animate(me,"idle",my.ANIMATION,ANM_CYCLE);

      c_scan(my.x,my.pan,vector(360,0,750),SCAN_ENTS | SCAN_FLAG2 | IGNORE_ME);

      if (you)
      {
         ...

         ent_movepath(me, "path_000", 2, 1+2);

         ...
      }

      ...

      ent_bonerotate(my, "Bip01 Spine1", vector(limit2,limit,limit3));
      
      my.tilt = 0;
      my.roll = 0;

      wait(1);
   }
}



It seems that the monster will move along the path if the ent_movepath() is set before the while(1) loop, but not if the ent_movepath() is set within the while(1) loop. I only want the monster to follow the path if the player triggers its c_scan() function, that is within the while(1) loop. Is this allowed with the ent_movepath() function?

NOTE: The program even acts strangely if I place the ent_movepath() function before the while(1) loop. If I specify where in the level I want the monster to be placed using the ent_create() function, the monster will be there where I specified, before the c_scan() is triggered - to which the monster disappears altogether.

If the ent_movepath() function is before the while(1) loop, the monster will not be where I specified, being totally non-visible. After awhile, the monster shows up coming up from underneath the floor (bottom of the spiral staircase room) where the "path_000" begins, and starts moving up the spiral staircase, along the "path_000" path, from bottom to top. I actually placed the monster a little ways up along the spiral staircase, so how it moves underneath the spiral staircase room is beyond me.
Posted By: Anonymous

Re: Path makes NPC disappear - 10/29/15 22:36

Hello ,

A few thing to say in no good order
First - I have told you not to check if(you) as a Boolean. YOU' will ALWAYS have a value, if c_scan finds nothing YOU still has a value. If you do no want to compare pointer 'if(you ==player), then set YOU=0; before the scan.
Next - you are not setting IGNORE_ME, I realize the SCAN_FLAG2 may be used to stop the ME ent from being found and return into the YOU pointer. However if the monster has flag2 set then infact it will find itself and return it's own pointer into the YOU pointer.

Code:
//before loop...
var im_on_path=0;
// in loop................................
you=NULL;
c_scan(my.x,my.pan,vector(360,0,750),SCAN_ENTS | SCAN_FLAG2 | IGNORE_ME);

      if (you && !im_on_path)
      {
        im_on_path=1;
         ...

         ent_movepath(me, "path_000", 2, 1+2);

         ...
      }



Next paths in wed have 2 names, one name is this WED list name and it's not important , the second name is it's real name. IN WED -> click path to select it, -> look at it's properties tab -> ignore name in path box, check name in NAME bow.
Make sure you have the right path name E1513 in the ent_movepath function can only be caused by -> the ME pointer is invalid or the path name is ivalid.

Last - Start a new level -> copy the path however put it in a empty hollow cube, -> add the player and monster to this new test level -> include you script with the actions for player/monster. Run you'r test in a big empty level so you can see what the heck happens to the monster when the player comes near.

Final - Always test new code and re-actions in small mostly empty test-level. If it works in the test then you can add it to a larger real level. Your game level is for play testing not for learning by trail.

Have fun
Mal
Posted By: Anonymous

Re: Path makes NPC disappear - 10/29/15 23:09

Here is the actual function from the entmove.c file.

Code:
function ent_movepath(ENTITY* ent,char* pathname,var speed,var mode)
{
	proc_kill2(ent_movepath,ent);
	var vLastPos[3],vDir[3];
	vec_set(vLastPos,ent.x);
	var dist = 0;
	if(pathname) path_set(ent,pathname);
	while(speed) 
	{
// place the entity along the path
		path_spline(ent,ent.x,dist);
		dist += speed*time_step;
// adjust the entity to the floor
		if(mode&1)
			ent_placefloor(ent);
// let the entity look ahead in movement direction
		if(mode&2) {
			vec_diff(vDir,ent.x,vLastPos);
			vec_to_angle(ent.pan,vDir);
			vec_set(vLastPos,ent.x);
		}
		var ehandle = handle(ent);
		wait(1);
		ent = ptr_for_handle(ehandle);
	}
}



As I fallow this, I think only if the MY pointer is invalid you would get e1513

You could include a local version of this function and not use the entmove.c version, then you can add some debugging to track it.

EDIT - When continuing after the e1513 , you state the monster walks blind forward. I would then think - if no other code is moving it - that path_spline is moving it, but failing somehow do to path_set being invaild.. However I'm not going to do a bunch of testing.
EDIT2 - One more note, path_spline moves the ent Without collision. For this reason I wrote my own path function. Based on what you report, I think the monster is moving without collsion to node 0/1(whatever) through the floor. That is why it pops up at the first node through from below the floor, Then the crash might be ent_placefloor()
Have fun
Mal
Posted By: Ruben

Re: Path makes NPC disappear - 10/30/15 02:40

Interesting. I made the path much smaller along the spiral staircase.

Now when my player triggers the c_scan(), I get the same pop-up error I mentioned before, and the monster warps from where I put it a little ways up on the spiral staircase, to the beginning node of the path at the bottom of the spiral staircase. This time, the monster is not coming from underneath the floor, but simply starts at the beginning node of the spiral staircase path, on top of the floor.

The monster then moves up the spiral staircase with no walking animation, even though I put the animation there. It just moves up the staircase path motionless.
Posted By: Anonymous

Re: Path makes NPC disappear - 10/30/15 03:43

It would seem the monster function crashes(clicking 'ok' you continue to run the program,however the bad function never runs again .i.e. monster_code)) , however the loop inside ent_movepath is still running. The ent_animate is in the monster loop that has crashed, so stops running.

Anyway good luck have fun. I got no answers for you, there is a reason that I don't use that function. Also i see the " ....." and there have been times your issues were with code inside the "...."
Track down you e1513, also that function - the monster will always "wrap" to the first node.
Posted By: Anonymous

Re: Path makes NPC disappear - 10/30/15 03:55

You can modify my basic path function found here
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Main=54661&Number=455425#Post455440

You my have add so math to smooth the between nodes like path_spline does.

By setting the node number closest to the monster here
my.NODE_NEXT=path_nextnode(my,1,1); // SET THE NODE
you can avoid the wrapping.

I am providing no more support for this, Unless I get bored when the weekend and drinks run out.
Mal
Posted By: Ruben

Re: Path makes NPC disappear - 10/30/15 16:41

I have had my fill of ent_movepath(). It is not a user friendly function.

You mentioned you stay away from this function. Do you know of a better way to accomplish what I am trying to accomplish?
Posted By: Anonymous

Re: Path makes NPC disappear - 10/30/15 19:35

^ um see my post above ^ ????
Posted By: Ruben

Re: Path makes NPC disappear - 10/30/15 21:43

Your function seems to partially work. I am still trying to adapt it to my code to possibly make it work.

In the meantime, I found another possible solution that seems to work mostly well. I am using ent_moveto() and ent_turnto() functions. They seem to be moving the monster down the staircase as needed. The only problem is that I am using a wait_for_my(ent_moveto) function that seems to prevent any animations from occurring, such as a running animation, until the ent_moveto() is finished.

Here is the code I am using to do this:

Code:
action monster_code()
{
   ...

   ent_animate(my, "run", anim_percentage, ANM_CYCLE); // This does not work 
                                       //    with the wait_for_my(ent_moveto)
                                       //    below.
   anim_percentage += 8 * time_step;

   ent_moveto(me, vector(322,555,196), 4); // 1st location down spiral staircase
   ent_turnto(me, vector(360,0,0), 4);
   wait_for_my(ent_moveto);
   ent_moveto(me, vector(617,37,120), 4); // 2nd location down spiral staircase
   ent_turnto(me, vector(300,0,0), 4);
   wait_for_my(ent_moveto);   // wait until target position reached        
   ent_moveto(me, vector(315,-442,49), 4); // 3rd location down spiral staircase
   ent_turnto(me, vector(240,0,0), 4);
   wait_for_my(ent_moveto);

   ...
}



If I take out all the wait_for_my() code, the running animation will happen, but the monster entity will move through the air directly from the 1st spiral staircase location to the 3rd location. The wait_for_my() functions make it so that the monster entity reaches the next location before turning and moving toward the next location given. The ent_turnto() seems to work with the wait_for_my() function calls, just not the running animation.

If I took out just the last wait_for_my() function call out of the above code, the monster would move and face the correct destinations while gliding with no animation. Once it got past the second destination though, it would start a running animation while it was being moved using ent_moveto(), so it is clear that the wait_for_my() function is what is causing the running animation to not occur.

Is there a way to allow the running animation to keep going even though the wait_for_my() function is being used?

This method seems to work perfectly, except for the fact that the monster does not appear to be running, only gliding toward the right directions with no animation.


Posted By: Anonymous

Re: Path makes NPC disappear - 10/30/15 21:59

At this time, I am evoking this -
Quote:
I am providing no more support for this, Unless I get bored when the weekend and drinks run out.


I'm a six-pack in already and it's a fun holiday weekend.

Best luck
Mal
Posted By: Ruben

Re: Path makes NPC disappear - 10/31/15 00:24

Originally Posted By: Malice
You can modify my basic path function found here
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Main=54661&Number=455425#Post455440

You my have add so math to smooth the between nodes like path_spline does.

By setting the node number closest to the monster here
my.NODE_NEXT=path_nextnode(my,1,1); // SET THE NODE
you can avoid the wrapping.

I am providing no more support for this, Unless I get bored when the weekend and drinks run out.
Mal

I tried using your function. The monster does run toward the first node, but does not go beyond the first node.

I am trying to figure out how to make it go to the second node.
Posted By: Anonymous

Re: Path makes NPC disappear - 10/31/15 00:47

Quote:
At this time, I am evoking this -
Quote:
I am providing no more support for this, Unless I get bored when the weekend and drinks run out.


I'm a six-pack in already and it's a fun holiday weekend.

Best luck
Mal


You obviously do not read what I post. That function works. It was the core of my space race game. I can write it, rewrite, mod it and make it give birth to little 3d puppies.

Good NIGHT
Mal
Posted By: Superku

Re: Path makes NPC disappear - 10/31/15 08:57

Ruben if your character does not go past the first node you obviously have to check the code and the comparisons involved which handle getting new nodes. From a first glance this seems to be stuff like this:
Code:
if(vec_dist(my.x,vec_next_node.x) < my.max_x)


Use draw_point3d to display let's say my.x and vec_next_node.x. You can use draw_line3d too.
Then DEBUG_VAR or draw_num3d (http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=455738#Post455738) to check both the vec_dist and my.max_x values, and draw my.NODE_NEXT.
Oftentimes nodes and such can have different heights compared to where "my.z" is, let's say when the origin of your model is rather low and the path node z values at a too high position. Then xy-dist will get as close as it gets but the z-difference can, because of your gravity code and such, remain too big. If you only have one floor you can set the vec_next_node.z value always to my.z.
Posted By: Anonymous

Re: Path makes NPC disappear - 11/01/15 07:23

^ Of course Superku is correct. The code was write to in current form for 2d movement - no z changes. It's clear in the line Superku points out and the lack of a Z-axis in the c_move of the code.

This correct can help
Code:
action ....()
{
var fxd_car_length =2.5; // A factor for the mulling the length of the models d-plane, current setting will more then double, reduce or increase at 0.25 increments as needed.

//......................................................
// my.max_x-my.min_x == total length from back x bbox plane to front x bbox plane Mulled by a factor of 2.5 , should mean even if there is a z-axis drop, this abs dist-num should be long enough. 
// Note to add the my.min_x value always "-" sub it, it is stored a a negative number. 
if(vec_dist(my.x,vec_next_node.x) < (my.max_x-my.min_x) * fxd_car_length )    
		{



Happy Halloween, I've got a ghost in my bed and she wants to rattle the chain. So have fun and game-on
Mal
Posted By: Ruben

Re: Path makes NPC disappear - 11/01/15 21:05

Okay, I managed to get Malice's function to work for my game. I had to change:
Code:
if(vec_dist(my.x,vec_next_node.x) < my.max_x)
to
if(vec_dist(my.x,vec_next_node.x) < 80)


I also used this c_move() code in my monster_code() action:
Code:
c_move(my, vector(8 * time_step, 0, 0), nullvector, GLIDE);



Now it seems to be working, from what I can tell. Thank you Malice and Superku.
Posted By: Anonymous

Re: Path makes NPC disappear - 11/02/15 09:18

Cool
© 2024 lite-C Forums