0 registered members (),
1,397
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
simple path following?
#316992
03/28/10 14:24
03/28/10 14:24
|
Joined: Oct 2009
Posts: 49
Lecithin
OP
Newbie
|
OP
Newbie
Joined: Oct 2009
Posts: 49
|
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.
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!
|
|
|
Re: simple path following?
[Re: Lecithin]
#316993
03/28/10 14:34
03/28/10 14:34
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
Serious User
|
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
temp is supposed to be a vector, not a variable. Try changing it to 'VECTOR temp;'.
Last edited by DJBMASTER; 03/28/10 14:34.
|
|
|
Re: simple path following?
[Re: Lecithin]
#316998
03/28/10 15:10
03/28/10 15:10
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
Serious User
|
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
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.
Last edited by DJBMASTER; 03/28/10 15:10.
|
|
|
Re: simple path following?
[Re: DJBMASTER]
#316999
03/28/10 15:17
03/28/10 15:17
|
Joined: Oct 2009
Posts: 49
Lecithin
OP
Newbie
|
OP
Newbie
Joined: Oct 2009
Posts: 49
|
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 :-)
Last edited by Lecithin; 03/28/10 15:18.
|
|
|
Re: simple path following?
[Re: Lecithin]
#317019
03/28/10 16:49
03/28/10 16:49
|
Joined: Oct 2009
Posts: 49
Lecithin
OP
Newbie
|
OP
Newbie
Joined: Oct 2009
Posts: 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)...
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.
|
|
|
Re: simple path following?
[Re: Lecithin]
#317077
03/29/10 07:40
03/29/10 07:40
|
Joined: Dec 2006
Posts: 1,086 Queensland - Australia
Nidhogg
Serious User
|
Serious User
Joined: Dec 2006
Posts: 1,086
Queensland - Australia
|
Have a look at c_move in the manual it has a good example of a basic walking script with gravity and floor detection.
Windows XP SP3 Intel Dual Core CPU: E5200 @ 2.5GHz 4.00GB DDR3 Ram ASUS P5G41T-M LX PCIE x16 GeForce GTS 450 1Gb SB Audigy 4 Spyware Doctor with AntiVirus
|
|
|
Re: simple path following?
[Re: Lecithin]
#317379
03/31/10 05:50
03/31/10 05:50
|
Joined: Dec 2006
Posts: 1,086 Queensland - Australia
Nidhogg
Serious User
|
Serious User
Joined: Dec 2006
Posts: 1,086
Queensland - Australia
|
Check your nodes maybe they are to close to the floor or something.
Windows XP SP3 Intel Dual Core CPU: E5200 @ 2.5GHz 4.00GB DDR3 Ram ASUS P5G41T-M LX PCIE x16 GeForce GTS 450 1Gb SB Audigy 4 Spyware Doctor with AntiVirus
|
|
|
Re: simple path following?
[Re: Nidhogg]
#317427
03/31/10 16:32
03/31/10 16:32
|
Joined: Oct 2009
Posts: 49
Lecithin
OP
Newbie
|
OP
Newbie
Joined: Oct 2009
Posts: 49
|
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 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.
Last edited by Lecithin; 03/31/10 23:32.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|