Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 16,232 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
vec_dist with x and y #423626
06/02/13 12:12
06/02/13 12:12
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
hi, I'm trying to make a short program that will generate the floor as the player moves through it.
I have a test pawn with the pointer "rogue" that I'm moving around with some c_move commands to test.
here is the action I'm using on the tiles that make up the ground:
Code:
action square()
{
	var end_peice = 1;
	while (end_peice == 1)
	{
	//	DEBUG_VAR(my.x, 150); 
		if (vec_dist(my.y, rogue.y) <= 500 && rogue.y <= my.y)
		{
			ent_create("space.mdl", vector (my.x, my.y+139, my.z), square);
			end_peice = 0;
		}
		if (vec_dist(my.y, rogue.y) <= 500 && rogue.y >= my.y)
		{
			ent_create("space.mdl", vector (my.x, my.y-139, my.z), square);
			end_peice = 0;
		}
		if (vec_dist(my.x, rogue.x) <= 500 && rogue.x >= my.x)
		{
			ent_create("space.mdl", vector (my.x-139, my.y, my.z), square);
			end_peice = 0;
		}
		if (vec_dist(my.x, rogue.x) <= 500 && rogue.x <= my.x)
		{
			ent_create("space.mdl", vector (my.x+139, my.y, my.z), square);
			end_peice = 0;
		} 
		wait (1);
	}
	ent_morph(me, "ender.mdl");
}



The idea here is that when the player is close enough it will generate a new tile in the proper direction,
and then set the variable "end_peice" to 0, so that it won't create any more tiles.
the ent_morph at the end shows me which ones have the variable set to 0 and wihich are still at 1.
some strange things are happening though. When I spawn the player is in the middle of a big square of tiles.
The tiles on the far right and left have end_peice set to 1, while all the rest have it set to 0.
So nothing happens when I move vertically, but an entire column of nine tiles appears when I move horizontally.
Also if I get far enough on the y-axis in either direction it suddenly tells me not enough entities were reserved and crashes.
I'm hoping I'm just doing something silly since I haven't used the vec_dist command this way before.
Thanks in advance, Rtsgamer706

Re: vec_dist with x and y [Re: rtsgamer706] #423629
06/02/13 12:47
06/02/13 12:47
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
vec_dist(my.y, rogue.y)
is not a valid use of the function and vectors in general. vec_dist has 2 VECTOR* parameters, not vars, thus the function will assume
(my.y,my.z, whatever follows in the memory)
as the vector you want to use.
The "distance" of two vars obviously is abs(my.y-rogue.y); which is equal to but faster than vec_dist(vector(0,my.y,0),vector(0,rogue.y,0));


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: vec_dist with x and y [Re: Superku] #423631
06/02/13 12:58
06/02/13 12:58
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
that might help, thanks

Last edited by rtsgamer706; 06/02/13 12:58.
Re: vec_dist with x and y [Re: Superku] #423632
06/02/13 13:02
06/02/13 13:02
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
that kind of helped, the code makes a lot more sense now,
but now all the squares except the corners have end_peice set to 0 and don't spawn squares
Also if I move just a little bit in any direction it crashes from running out of entities.

Re: vec_dist with x and y [Re: rtsgamer706] #423643
06/02/13 15:51
06/02/13 15:51
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
Here's the new code, if that might help:
Code:
action square()
{
	var end_peice = 1;
	while (end_peice == 1)
	{
	//	DEBUG_VAR(my.x, 150); 
		if (abs(my.x - rogue.x) <= 500 && rogue.x <= my.x)
		{
			ent_create("space.mdl", vector (my.x+139, my.y, my.z), square);
			end_peice = 0;
		}
		if (abs(my.x - rogue.x) <= 500 && rogue.x >= my.x)
		{
			ent_create("space.mdl", vector (my.x-139, my.y, my.z), square);
			end_peice = 0;
		}
		if (abs(my.y - rogue.y) <= 500 && rogue.y >= my.y)
		{
			ent_create("space.mdl", vector (my.x, my.y-139, my.z), square);
			end_peice = 0;
		}
		if (abs(my.y - rogue.y) <= 500 && rogue.y <= my.y)
		{
			ent_create("space.mdl", vector (my.x, my.y+139, my.z), square);
			end_peice = 0;
		}
		wait (1);
	}
	ent_morph(me, "ender.mdl");
}



Gamestudio download | 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