Calculating distances

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
LordTyphoon
Posts: 33
Joined: Mon Sep 29, 2008 12:52 pm
Location: Montreal, QC, CA

Calculating distances

Post by LordTyphoon »

So, here is what I am trying to do: I am trying to calculate the distances between the player and a monster. This is strictly from a debug point of view so far.

When the map starts, the player is given a tId of 1000

Code: Select all

script 999 enter //Attributes tId of 1000 to the player
{
	Thing_ChangeTID(0, 1000);
}
I then have this script, which I run from console, calculating the distance between the player and the actor the player is aiming at using the wiki's distance function and then printing it

Code: Select all

script 994 (void)
{
	SetActivatorToTarget(0);
	print(d:distance(1000,ActivatorTid()));
}

Code: Select all

function int sqrt (int x)
{
	int r;
	x = x + 1 >> 1;
	while (x > r)
		x -= r++;
	return r;
}

function int distance (int tid1, int tid2)
{
	int x, y, z, d;
	x = GetActorX(tid1) - GetActorX(tid2) >> 16; // Convert fixed point to integer
	y = GetActorY(tid1) - GetActorY(tid2) >> 16;
	z = GetActorZ(tid1) - GetActorZ(tid2) >> 16;
	d = sqrt( x*x + y*y + z*z );
	return d;
}
When aiming at nothing, puke 994 prints 0 on the screen. Fair enough, the distance between the player and the player is 0.

But when aiming at an Imp..
nothing happens. Nothing is printed. I suppose the script dies somewhere along the line, but for the life of me I can't make heads or tails of it.
Any help would be greatly appreciated. :)
User avatar
corysykes
Posts: 329
Joined: Mon May 07, 2007 6:03 pm
Location: Location i have no Location

Re: Calculating distances

Post by corysykes »

can you post the wad? but i think it might have something to do with the fact that your giving every thing a thing id of 0 a thing id of 1000 but that goes to show you that i dont use that function much so i dont know.the script its self looks logically correct.
User avatar
LordTyphoon
Posts: 33
Joined: Mon Sep 29, 2008 12:52 pm
Location: Montreal, QC, CA

Re: Calculating distances

Post by LordTyphoon »

The first script shouldn't give everything a tId of 1000. It runs only once (when the map starts) and I think I'm right when I say ACS logic assumes the script activator is the player, so SetActivatorTid(0, 1000) gives only the activator (that's what the 0 does usually) a tid of 1000.

I'll see about whipping up something to upload
User avatar
oODemonologistOo
Posts: 318
Joined: Tue Jul 17, 2007 10:30 am
Location: one of the labs of hell

Re: Calculating distances

Post by oODemonologistOo »

Using cuberoot may help. It is for 2d distances you use square root, maybe you need cube root for 3rd dimension calculations.
Locked

Return to “Editing (Archive)”