I use this code to create a model to follow the player but it can't find the crumbs.

you can see my problem in this video:
http://vimeo.com/30239469

Code:
////////////////////////
ENTITY* target_crumb;

function crumb_init()
{
	my.passable=on; // player's movement code should ignore passable entities
	my.z -=60 ; // experimental value, keeps npc's feet on the floor
	my.enable_scan=on;
}

function breadcrumbs()//sakht box namri donbale player
{
	wait(-3);//wait til player fix its position
	var player_pos1[3];
	var player_pos2[3];
	var step = 1;
	// make sure that player's action includes a "player = my;" line of code
	while (!player) {wait (1);} 
	while (1)
	{
		if (step == 0)
		{
			step = 1;
			vec_set(player_pos1.x, player.x); // store the initial player position
		}
		vec_set(player_pos2.x, player.x); // store the initial player position
		if (vec_dist (player_pos2.x, player_pos1.x) > 100) // create a breadcrumb every 50 quants
		{
			// allow player_pos1 to be set to a new value (approximately equal with the last player_pos2 value)
			step = 0; 
			ent_create("crumb.mdl", player.x, crumb_init);
			
		}
		wait (1);
	}
}
//////////////////////////////
function morph_to_actor2()
{
	var temp[3];

	while(1)
	{
		// don't do anything if the player is very close
		my.skill22 = 0;
		while (vec_dist(player.x, my.x)<300)
		{
			my.skill22 += 1 * time_step; // 4 gives the "stand" animation speed
			ent_animate(my, "stand", my.skill22, ANM_CYCLE);
			wait (1);
		}

		c_scan(my.x, my.pan, vector(360, 30, 500), SCAN_ENTS | SCAN_LIMIT|IGNORE_ME); // scan for crumbs that are placed up to 1000 quants
	
		if (you) // a crumb was detected?
		{
			target_crumb = you; // the closest crumb to the npc is set to "you" by c_scan
			// rotate the npc towards the crumb		
			vec_set(temp, target_crumb.x);
			vec_sub(temp, my.x);
			vec_to_angle(my.pan, temp);
			
			while (vec_dist (my.x, target_crumb.x) > 30) // the npc moves until it comes close to target_crumb
			{
				my.skill22 += 5 * time_step; // 5 gives the "walk" animation speed
				c_move(my, vector(10 * time_step, 0, 0), nullvector, IGNORE_PASSABLE | GLIDE);
				ent_animate(my, "walk", my.skill22, ANM_CYCLE);
				wait (1);
			}		
			ent_remove(target_crumb); // so remove the current target_crumb and prepare for the following crumb

		}
		wait(1);
	}
}
}



Last edited by parsgame; 10/08/11 19:30.