Game Development Community

t2dVetcorDistance

by rennie moffat · in Torque Game Builder · 04/15/2010 (7:41 am) · 10 replies

Hi, the t2dVectorDistance() is supposed to compare 2 vectors and return a float value, however, my return in echo is a vector. What giveth?



%this.tile1Distance = t2dVectorDistance(%this.templePos, %this.tile1Pos); 
echo("   %this.tile1Distance " @ %this.tile1Distance);


About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
04/15/2010 (9:05 am)
t2dVectorDistance should, in fact, return a float. I just executed the following and it returned a float.
echo(t2dVectorDistance("10 12", "25 15");
Can you post your output of the echo?
#2
04/15/2010 (9:27 am)
oh ok, I thought that was a vector, 2 in fact.

I am getting something like that say "30 88".

The thing is, I am trying to compare the distance between a moving object and a static object, several static objects in fact and depending on which is closet to the moving object a third object will move to the static object closest to the moving object. Make sense?


So at the end of the day I want to determine the shortest distance between one object and several others. Where the one object can move (changes distance) and the others are static, in that they can not move.

#3
04/15/2010 (9:48 am)
Quote:
Make sense?
Not really... :)

The fact that you're getting a vector back from that function doesn't make sense to me at all. Whether the objects are moving or not, it shouldn't matter. It should give you the distance between those objects at the instant you called the function.

If you paste the following into your console while the game is running, what do you get echo'd back?

echo(t2dVectorDistance("10 12", "25 15"));
#4
04/15/2010 (9:54 am)
echo(t2dVectorDistance("10 12", "25 15") returned 15.2971 or something like that. a Float!

hooray, but when am I getting vectors?

#5
04/15/2010 (10:06 am)
I used those specific numbers to eliminate the possibility that the positions (%this.templePos, %this.tile1Pos) you were passing to the functions had errors in them.

This is a way to overcome code isues. You first isolate the problem, then test the function in question. This way, we know that "10 12" and "25 15" are valid vectors.

When I execute echo(t2dVectorDistance("10 12", "25 15")); in the console I get: 15.2971 back which tells me that the t2dVectorDistance function is working fine.

If you aren't getting anything back, maybe you overrode the t2dVectorFunction somewhere in your code and that is why you are getting unexpected results.
#6
04/15/2010 (10:08 am)
OK, so echo out %this.templePos and %this.tile1Pos before you try to get the distance and see if you're passing it an unexpected value.
#7
04/15/2010 (10:16 am)
yah I have I am getting vectors returned.




:::?
#8
04/15/2010 (10:31 am)
...and what values echo out?
#9
04/15/2010 (11:42 am)
this is odd... now it does return 0, a good sign I guess as its one number, the thing that gets me is that my tile1Pos, tile2Pos which echoing are not now. this is proving to be very fidgety. No worries tho as I say it did, was working, those echos anyway.


:::??????!!!
#10
04/15/2010 (11:54 am)
ok this is weird.


I have my echo is not even calling.


echo(" %this.tile9Pos " @ %this.tile9Pos);
in my onUpdate. tile9Pos is called in onBehavior add. very primitive stuff here.



rrrrrr.