1 registered members (AndrewAMD),
1,507
guests, and 12
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
vec_dist with x and y
#423626
06/02/13 12:12
06/02/13 12:12
|
Joined: Dec 2009
Posts: 361
rtsgamer706
OP
Senior Member
|
OP
Senior Member
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:
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
Senior Expert
|
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
rtsgamer706
OP
Senior Member
|
OP
Senior Member
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: rtsgamer706]
#423643
06/02/13 15:51
06/02/13 15:51
|
Joined: Dec 2009
Posts: 361
rtsgamer706
OP
Senior Member
|
OP
Senior Member
Joined: Dec 2009
Posts: 361
|
Here's the new code, if that might help:
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");
}
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|