Gamestudio Links
Zorro Links
Newest Posts
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (Petra, AndrewAMD, Quad, VoroneTZ, 1 invisible), 488 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Again new question about path patrol :) #454209
09/01/15 10:48
09/01/15 10:48
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
I use this script and it works. The model walks to the end of the path then gets to the start point again and so on.

I've learned thanks to JCL also how to remove the character at the end of the path. Now the final thing i would like to understand is how to make the model go back at the end of the path the same route instead of running straight to the starting point laugh

thank you for your time laugh

Code:
action moveontrack_01()
{
	var walk_percentage;
	var walking_speed = 0.3;
	VECTOR last_pos[3];

	VECTOR direction[3];
	var distance = 0;
	var dist_to_node;

	var current_node = 1;
	
	set(my,SHADOW|PASSABLE);
	path_set(me, "path_000"); 
	while(1) 
	{
		ent_animate(my, "run", walk_percentage, ANM_CYCLE); // play the "walk" animation
		walk_percentage += 6 * time_step; // "3" controls the animation speed
		path_spline(me, my.x, distance);
		distance += walking_speed ;
		vec_diff(direction, my.x, last_pos);
		vec_to_angle(my.pan, direction);
		vec_set(last_pos, my.x);


		wait(1);

	}
}



Last edited by Realspawn; 09/01/15 10:48.

Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: Again new question about path patrol :) [Re: Realspawn] #454216
09/01/15 13:41
09/01/15 13:41
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
you will need to modify back to zero the 'distance' variable once reached the total length by converting the 'walking_speed' variable to a negative value.

You will need to get the total length of a path by 'path_length' before the loop.
Code:
var nPathLength = path_length ( me );



Then check the distance value inside the loop and switch the walking speed variable sign.
Code:
nDistance += nWalkingSpeed * time_step;
if ( ( nDistance < 0 ) || ( nDistance > nPathLength ) )
{
   nWalkingSpeed *= -1;
   nDistance = clamp ( nDistance, 0, nPathLength );
}



There are a couple of troubles in your code. You declared 'last_pos' and 'direction' as arrays of three vector structs. You only need one vector struct each.
Code:
VECTOR vecDirection; // A single vector struct
VECTOR vecDirection[3]; // An array of vector structs
VECTOR *vecDirection; // A single pointer to a vector struct
VECTOR *vecDirection[3]; // An array of pointers to vector structs



You modify the 'distance' variable by adding the 'walking_speed' constant value. This method is framerate dependant. You need to multiply it by 'time_step' in order to certainly convert a speed to a distance in reference to a time lapse.

Hope it helps. Salud!

Re: Again new question about path patrol :) [Re: txesmi] #454217
09/01/15 13:43
09/01/15 13:43
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
great thank you so much grin i will start testing this right away grin


Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: Again new question about path patrol :) [Re: Realspawn] #454218
09/01/15 14:21
09/01/15 14:21
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
glad to help laugh

Re: Again new question about path patrol :) [Re: txesmi] #454223
09/01/15 15:41
09/01/15 15:41
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
not doing well so far but keep ttrying lol

why do you have the letter N infront of all ?


Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: Again new question about path patrol :) [Re: Realspawn] #454225
09/01/15 16:03
09/01/15 16:03
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
I use my own version of the hungarian notation.
n for vars: nDistance
i for integer: iIndex
str for strings: strName
vec for vector: vecPosition
ang for angles: angOrientation
ent for entities: entPlayer
and so on...

It enhances the readability of the code a lot.

Re: Again new question about path patrol :) [Re: txesmi] #454227
09/01/15 16:22
09/01/15 16:22
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
It works laugh i am sure this code is not perfect but it works
are there thing i should change about this to make it
a perfect clean code ?

thank you for you help it drove me nuts lol

Code:
ENTITY* walker01;

action moveontrack_01()


{
	var walk_percentage;
	var distance = 0;
	var walking_speed =10;
	VECTOR vecLastposition; 
	VECTOR vecDirection; 
	var vDir[3];
	
	walker01 =me;
	path_set(me, "path_000");
	var nPathLength = path_length ( me ); 

	while(1) 
	{
		path_spline(walker01, my.x, distance);
		vec_diff(vDir,my.x,vecLastposition);
		vec_to_angle(my.pan,vDir);
		vec_set(vecLastposition,my.x);



		

		distance += walking_speed * time_step;
		if ( ( distance < 0 ) || ( distance > nPathLength ) )
		{
			walking_speed *= -1;
			distance = clamp ( distance, 0, nPathLength );
		}
		
		wait(1);
		
		ent_animate(my, "walk", walk_percentage, ANM_CYCLE); // play the "walk" animation
		walk_percentage += 5 * time_step; // "3" controls the animation speed
	}
}



Last edited by Realspawn; 09/01/15 16:38.

Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: Again new question about path patrol :) [Re: Realspawn] #454234
09/01/15 19:53
09/01/15 19:53
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
I am not the man to talk about perfection but I can see some little improvements can be done.

I guess your path is contained in a horizontal plane. If so, you can compute the entity pan angle with trigonometrics and save some microticks.
Code:
my.pan = atan2v ( my.y - vecLastposition.y, my.x - vecLastposition.x );



'vecDirection' is declared but not used. I would delete the 'vDir' array and use 'vecDirection' instead.

Put the 'wait' instruction at the end of the loop. It is a good practice. Add it at other place when has a clear purpose and is needed. There is no problem as it is anyway.

Be consistent with spaces and line breaks. If one line has spaces between operators, parameters, etc and the next one has no spaces the reading is blurred. Especially when the reader has no idea.

Use some sort of hungarian notation. It really deserves the effort. grin

Re: Again new question about path patrol :) [Re: txesmi] #454237
09/01/15 21:01
09/01/15 21:01
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
Super it all works laugh because this works i had no problem now to make it remove at the end point laugh and to make it restart at the beginning laugh

thank you for hinting pointing me in the right direction laugh

Last edited by Realspawn; 09/01/15 21:07.

Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1