Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,507 guests, and 12 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 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 | 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