how to make friends follow you in a good way?

Posted By: Muhsin

how to make friends follow you in a good way? - 05/21/10 12:54

Hi!

I'm programing friend npc, who I can make following me.
the problem is, when I got more then one friend, and they try to follow me, they walk into each other.

how can I make them not touch each other and still follow me?

here is the friend code so far:
------------------------------------------------------
action skinnyfriend()
{
my.HEALTH = 100;

var follow_mode = false;
VECTOR temp;
VECTOR skinnyfriend_distance;

while(my.HEALTH > 0)
{
if(player)
{

if(follow_mode == true)
{

vec_set(temp, player.x);
vec_sub(temp, my.x);
vec_to_angle(my.pan, temp);
my.tilt = 0;



if(vec_dist(my.x, player.x) < 340 && vec_dist(my.x, player.x) > 50 && player.HEALTH > 0)
{

skinnyfriend_distance.x = 10 * time_step;
skinnyfriend_distance.y = 0;
skinnyfriend_distance.z = 0;

c_move(my, skinnyfriend_distance, nullvector, NULL);
ent_animate(my, "run", my.skill1, ANM_CYCLE);
my.skill1 += 9 * time_step;
if(my.skill1 > 100) {my.skill1 = 0;}
}

if(vec_dist(my.x, player.x) < 50 || player.HEALTH < 1)
{
ent_animate(my, "control", 1, ANM_CYCLE);
vec_set(temp, player.x);
vec_sub(temp, my.x);
vec_to_angle(my.pan, temp);
my.tilt = 0;
}

if(key_2)
{
follow_mode = false;
}
}

else if(vec_dist(my.x, player.x) < 70 && player.HEALTH > 0)
{
ent_animate(my, "control", 1, ANM_CYCLE);
vec_set(temp, player.x);
vec_sub(temp, my.x);
vec_to_angle(my.pan, temp);
my.tilt = 0;

if(key_1)
{
follow_mode = true;
}
if(key_3)
{
//shut up
}
if(key_4)
{
//run n' hide
}
}



else if(vec_dist(my.x, player.x) < 30 && player.HEALTH > 0)
{
c_move(my,vector(-1 * time_step, 0, 0), nullvector, GLIDE);
}

else if(vec_dist(my.x, player.x) < 150 && player.HEALTH > 0)
{
vec_set(temp, player.x);
vec_sub(temp, my.x);
vec_to_angle(my.pan, temp);
my.tilt = 0;

ent_animate(my, "shout", my.skill4, ANM_CYCLE);
my.skill4 += 9 * time_step;
if(my.skill4 > 100) {my.skill4 = 0;}
}

else
{
ent_animate(my, "idle", my.skill3, ANM_CYCLE);
my.skill3 += 1 * time_step;
if(my.skill3 > 100) {my.skill3 = 0;}
}

}

wait(1);
}
}
------------------------------------------------------

Thanks for the help!


- Muhsin Kaymak
Posted By: Pappenheimer

Re: how to make friends follow you in a good way? - 05/21/10 13:04

If its only the player who has friends wink , you can use a global variable which saves the amount of following friends, otherwise you have to use a skill and let the player scan from time to time whether friends are following.
Then you can spread places around the player which the friends are targetting instead of the player directly. Or, you can give the friends numbers, and, depending the numbers make them follow in a different distance.
Probably, they have to make a check whether there is already a friend between them and the player to stop them from trying to get closer ti the player.
Posted By: fogman

Re: how to make friends follow you in a good way? - 05/21/10 13:41

Another way: Let the player spread "breadcrumbs".
Create one breadcrumb for every friend.

Set the breadcrumbs to slightly different positions and give
every one a unique ID, so that the friends can determine their personal crumb.

Posted By: The_Clyde

Re: how to make friends follow you in a good way? - 05/21/10 20:22

Heres a link from my bookmarks that should help you:
http://www.red3d.com/cwr/steer/

It's got a bunch of pathfinding techniques that it explains and demonstrates how they work with Java applets.
Posted By: Muhsin

Re: how to make friends follow you in a good way? - 05/21/10 21:31

Now all the friends have ID. I'm still trying to figure out how to make them follow me the right way.

I will post, when i found out how to do it, until then any help might help grin

thanks for the helps!

- Muhsin Kaymak
Posted By: Muhsin

Re: how to make friends follow you in a good way? - 05/21/10 23:09

I found out how to do.

here is how I did:

1. giving ID's for the friends
2. create positions around the player(by using models as positions)(I used ent_create to create them in-game)
3. make the positions follow the player.
4. have the friends follow the positions.


thanks very much for the helps!


- Muhsin Kaymak
Posted By: 3run

Re: how to make friends follow you in a good way? - 05/22/10 03:02

Can u please upload example of what you've done? laugh
Posted By: Muhsin

Re: how to make friends follow you in a good way? - 05/22/10 09:24

yea, of course.

here is how I did:

first write "ENTITY* position1;" and "var friendcount" on the top of you script.

then in you player code write "ent_create("position1.mdl", nullvector, func_position1);" //it creats position1 model at the vector(0,0,0) and gives it the function "func_position1"

after that, create the function for the position, I did like this:

----------------------------------------
function func_position1()
{

position1 = me; //tells that it is the position1
set(my, PASSABLE); //makes it passable
set(my, INVISIBLE); //makes it invisible

while(1)
{
my.pan = player.pan; //pan as the player pan
my.x = player.x; //be on the same x as the player (if you want the position to be before or after the player, you write +something or -something after the x, like I did with the y.
my.y = player.y+50; //be on the same y+50 as the player
my.z = player.z; //be on the same z as the player

wait(1);
}
}
--------------------------------------------------------

then you go down to you friend code and give it a ID and make it go to its position, like this:

-------------------------------------------------------------------
action friend()
{
var tailnumber = 0;

friendcount = friendcount + 1; //this counts up the friendcount var in the top, when the friend has been created.

tailnumber = friendcount; //gives the friend an ID, by seen what the friendcount was on, when he was created.

while(1)
{

if(tailnumber == 1) //if the friend got the ID 1.
{
vec_set(temp, position1.x) //this will make it look at position1
vec_sub(temp, my.x); //this will make it look at position1
vec_to_angle(my.pan, temp); //this will make it look at position1
my.tilt = 0; //don't tilt, when looking

then you use c_move to make it walk toward its own x-axis. and because its x-axis is turned toward the position1, it will walk that way.
}

}
}

---------------------------------------------------------------------

it isn't the best way to do it, but it worked for me, so I use it.

I hope it was clearly enough. if you don't understand, then ask me and I will try to explain another way.


thanks


- Muhsin Kaymak

EDIT: I might be able to upload an example script later...if you got time to wait?
Posted By: 3run

Re: how to make friends follow you in a good way? - 05/22/10 21:01

Thank you boss laugh everything is clear. About an example, just upload it when you'll be able to laugh there is no need to hurry laugh Thank you again bro
Posted By: Muhsin

Re: how to make friends follow you in a good way? - 05/22/10 21:17

Ok, you example will be ready tomorrow..... or the day after tomorrow....hopefully grin


- Muhsin Kaymak
Posted By: 3run

Re: how to make friends follow you in a good way? - 05/22/10 21:34

Thank you any way man laugh And I'll be waiting for it laugh
Posted By: Muhsin

Re: how to make friends follow you in a good way? - 05/22/10 22:58

Hi!

I was able to finish a simpel example for following friends.

here is the download link: http://dl.dropbox.com/u/5394772/FFE.zip

hopefully it works! grin

thanks to everyone, who helped me make it!

- Muhsin Kaymak
Posted By: 3run

Re: how to make friends follow you in a good way? - 05/23/10 01:22

Thank you for it laugh
© 2023 lite-C Forums