Game Development Community

AddLinkPoint() going to the wrong place

by Tim Doty · in Torque Game Builder · 04/12/2005 (10:00 am) · 8 replies

I noticed that missiles weren't spawning from the correct position so I started digging into my code looking for the error and what I found puzzles me. (Including some debugging lines) the following is what I use to add the link point (and create the missile launcher). The %launchOffset is used to make the missile appear in front of the launcher instead of on top and the %location is an integer representing the vehicle side.

echo("*** Adding missile launcher");
    if (%location == 1) {
      %launchOffset = "0 -0.95";
      }
    else if (%location == 2) {
      %launchOffset = "0 0.95";
      }
    else if (%location == 3) {
      %launchOffset = "-0.95 0";
      }
    else if (%location == 4) {
      %launchOffset = "0.95 0";
      }
    else {
      %launchOffset = "0 0";
      echo("Unknown facing" SPC %location);
      }
    echo("Launch offset: " @ %launchOffset);
    echo("Launch position: " @ vectorAdd2D(%offset,%launchOffset));
    %this.weaponObject[%this.numberWeapons].weaponLinkPoint = %this.addLinkPoint(vectorAdd2D(%offset,%launchOffset));
    echo("Link point: " @ %this.getLinkPoint(%this.numberWeapons));
    %this.weaponObject[%this.numberWeapons] = missilelauncherObject::create("", %this, %weaponName, %location, %offset);

This produces the following in the console.log (%location is 1 in this case for the front of the vehicle):

Quote:
*** Adding missile launcher
Launch offset: 0 -0.95
Launch position: -0.200000 -1.550000
Link point: -1.500000 5.250000

The vehicle in question should be at 0,0 at this point. When the game is finished loading the vehicle is at 22.5,0 and if I do

==>$tlp = $player.addLinkPoint("-0.2 -1.55");
==>echo($player.getLinkPoint(1));

I get

Quote:
-23.250000 -11.625000

Which should be the correct offset. Any ideas as to why the first one is offset down instead of up?

#1
04/12/2005 (4:32 pm)
I realized a better illustration of the problem is this:

Quote:
*** Adding missile launcher
Launch offset: 0 -0.95
Launch position: -0.200000 -1.550000
Link point: -1.500000 5.250000
...
==>$tlp = $player.addLinkPoint("-0.2 -1.55");
==>echo($player.getLinkPoint(1));
-23.250000 -11.625000
==>echo($player.getLinkPoint(0));
-24.000000 5.250000

The code is as I showed previously so the second addLinkPoint() should be being called wtih the same parameters as the first. However, the one added after the game has loaded is placed differently (and correctly). The first is misplaced in both directions, although most wrongly in the Y.
#2
04/12/2005 (9:48 pm)
After close investigation I believe this is a bug and am reporting in the bugs.
#3
04/13/2005 (6:35 am)
Is the behaviour anything like this? A brief skim it sounds similiar.
#4
04/13/2005 (6:50 am)
@John: I don't believe so. That had to do with mounting and rotation issues. This is a matter of calling addLinkPoint() before using a mount(). Looking at the addLinkPoint code last night I didn't see any immediate reason for why it would behave this way, but from a torquescript perspective it didn't matter where addLinkPoint() was called other than whether or not a mount() was called before it.
#5
04/13/2005 (7:07 am)
Reason I asked was because mounts are simply linkpoints that are kept updated.
#6
04/13/2005 (7:18 am)
And it's certainly possible you're right, I haven't properly analyzed the T2D source code for this. But IIRC the problem you saw was related to doing rotations, mounting and unmounting and returning to previous positions. It is consistent with the incorrect value for the link point, but it is related to position or movement: nothing moves and yet the second one is correct while the first one is still incorrect.
#7
04/13/2005 (8:20 am)
I 'think' at one point someone posted a problem on the getLinkPoint function and its translation to world units... my memory is a bit fuzzy so I could be incorrect (very possible lol), but if so that fix might fix this in the new version :)
#8
04/14/2005 (12:46 pm)
Nah... neglected this thread, sorry, it turns out it was a simple bug on my part that I couldn't see. The reason it worked calling a second time was an accident of circumstance.

Thanks, all