simple path following?

Posted By: Lecithin

simple path following? - 03/28/10 14:24

I've searched the manual, tried the wiki, and looked at the forums for awhile now but I can't seem to figure this out. I've tried a few versions of code but each one gives a different problem :-/

I need a very simple script that allows an entity to follow a simple path. I know how to create the path but I can't seem to script the entity to follow it.

I used action patrol_path() in the manual but I get a "Crash in patrol_path" error... I added the var temp; part because w/out it I got another error.

Code:
action patrol_path()
 {
  result = path_scan(me,my.x,my.pan,vector(360,180,1000));     
  if (result == 0) { return; }

  var node = 1;
  path_getnode(my,node,my.skill20,NULL);

  while (1)
  {
    var temp;
    var angle[3];
    result = vec_to_angle(angle,vec_diff(temp,my.skill20,my.x));

    if (result < 25) 
    {
      node = path_nextnode(my,node,1);
      path_getnode(my,node,my.skill20,NULL);
    }

    my.pan = angle[0];
    c_move(me,vector(3*time_step,0,0),NULL,GLIDE);
    wait(1);
  }
}



What am I doing wrong? I'm sure this is very simple but I can't seem to put 2 + 2 together today. Thanks for your help!
Posted By: DJBMASTER

Re: simple path following? - 03/28/10 14:34

temp is supposed to be a vector, not a variable. Try changing it to 'VECTOR temp;'.
Posted By: Lecithin

Re: simple path following? - 03/28/10 14:46

thank you very much! I've got a lot to learn laugh
Posted By: DJBMASTER

Re: simple path following? - 03/28/10 15:10

No problem, at least you are doing the sensible thing and trying yourself, and then asking. The example in the manual is probably targeted for the older language C-Script as 'temp' was a built-in vector, rather than requiring the user to define it themselves.
Posted By: Lecithin

Re: simple path following? - 03/28/10 15:17

ah, I was going to ask that. I noticed it a lot in the example codes but in those same codes it wasn't defined beforehand.

I'm experimenting with getting the mage in workshop 24 to follow a path when out of range of the other mage and then changing his state and attacking when in range.

We'll see how it goes but with my current luck I might be asking more questions :-)
Posted By: Lecithin

Re: simple path following? - 03/28/10 16:49

Ok, I've gotten the character to follow the path and when the player's mage comes into c_scan range the AI mage begins attacking. All of that works flawlessly when the mage is approximately 50 pixels above the terrain but when I tried to set the mage on the terrain (using c_trace and hit.z etc) he only walks & animates until he hits the next node on the pathand then gets stuck. Once stuck he changes his pan incredibly quickly (essentially pointing one way then another) but doesn't move forward.

There's more to the code than this but the only pertinent part is (I think)...

Code:
action wizard_patrol()
{
	my.event = wizard_hit;
	my.emask |= ENABLE_IMPACT;   
	
	VECTOR vFeet;
	vec_for_min(vFeet,me);

  ENTITY* enemy = NULL; // spell target

	my.STATE = 1;
	
	result = path_scan(me,my.x,my.pan,vector(360,180,1000));     
	if (result == 0) { return; } 
	var node = 1; // start at first node
	path_getnode(my,node,my.skill20,NULL);
	
	while (1)
	{
		if(my.STATE == 1) 
		{		
		c_scan(my.x,my.pan,vector(360,0,750),SCAN_ENTS | SCAN_FLAG2 | IGNORE_ME);
		if (you) // red wizard or flying spell detected?
		    {
			my.STATE = 2; 
			enemy = your.CREATOR;
		    }
		else
		    {
		    VECTOR* temp = NULL;
		    var angle[3];
		    result = vec_to_angle(angle,vec_diff(temp,my.skill20,my.x));
		    if (result < 25) 
		        {
		        node = path_nextnode(my,node,1);
	                path_getnode(my,node,my.skill20,NULL);
		        }
		    my.pan = angle[0];
		    c_move(me,vector(3*time_step,0,0),NULL,GLIDE);
		    my.ANIMATION += 5*time_step;
		    ent_animate(me,"walk",my.ANIMATION,ANM_CYCLE);	
		    c_trace(my.x,vector(my.x,my.y,my.z-1000),IGNORE_ME | IGNORE_PASSABLE);
		    my.z = hit.z - vFeet.z;
	            }
                }



So I believe the problem is w/my c_trace. I adjusted the script to use this same exact code but place the wizard 50 pixels above the terrain and it works fine there so I believe my collisions are off for some reason.
Posted By: Nidhogg

Re: simple path following? - 03/29/10 07:40

Have a look at c_move in the manual it has a good example of a basic walking script with gravity and floor detection.
Posted By: Lecithin

Re: simple path following? - 03/30/10 14:10

I've checked out the c_move example and it is a great example of movement but my player's movement already worked. I learned a lot from that example but when I applied the pertinent parts to my code I still ended up with problems.

My problem isn't the player's character movement rather it's the AI wizard that's patrolling. He gets stuck when switching to the next node on the path but only gets stuck when he's on the ground, when floating approximately 50 quants up he does just fine.

I've even drawn out my formula and can't seem to find a problem but I'm new so who knows what I'm missing.

Suggestions?
Posted By: Nidhogg

Re: simple path following? - 03/31/10 05:50

Check your nodes maybe they are to close to the floor or something.
Posted By: Lecithin

Re: simple path following? - 03/31/10 16:32

ah, I figured part of the problem out. It's not the movement that's the problem its the path! He gets stuck once he gets to the path but he finds it perfectly. He can walk over mountains and all else, but my path is broken. I'm happy that I at least know what to try to fix now laugh


At least I thought.... now nothing seems to be working properly. I'm pretty sure its the path so I'll set my mind to attempting to fixing that.
Posted By: Lecithin

Re: simple path following? - 03/31/10 23:39

WOOOOO I got it. After hours of looking at the wrong thing it turns out my problem was with the following.

in the while(1) statememt...
Code:
result = vec_to_angle(angle,vec_diff(temp,my.skill20,my.x));

if (result < 25)
    {
	node = path_nextnode(my,node,1);
	path_getnode(my,node,my.skill20,NULL);
    }



apparently my path was having the wizard turn more than 25 (the returned value from vec_to_angle) and thus it wouldn't run the if (result < 25) statement since that statement never evaluated to true.

By increasing the value after the if it now works flawlessly!
© 2024 lite-C Forums