Page 1 of 1

Specifying escort postion

Posted: Mon Apr 11, 2011 8:44 am
by Smivs
Hi all,
Yet again my lack of understanding of js has reared it's head!
I want to place one escort in a specific position next to its Mother. After looking through the Wiki and BB I came up with this which is called from the mother's shipdata.plist

Code: Select all

this.coordinatesForEscortPosition = function ()
{
     this.EscortPosition(15, -80, 230);
}
which of course doesn't work. :roll:
help please!

Re: Specifying escort postion

Posted: Mon Apr 11, 2011 12:39 pm
by Killer Wolf
escort positioning has been reworked, here's my thread on it w/ code etc
https://bb.oolite.space/viewtopic.php?f= ... it=+escort

Re: Specifying escort postion

Posted: Mon Apr 11, 2011 1:11 pm
by Smivs
Thanks KW.
I'm not sure that is what I need though. My requirement is actually much simpler. I just want to spawn one escort in a precise position near the mother. It's a special case as neither will move at any time (the mother is actually a small station a bit like a rock hermit) so there is no formation to maintain, and I don't need or want the escort to move into position....I just need it to be there as the mother is spawned, in exactly the right position.

Re: Specifying escort postion

Posted: Mon Apr 11, 2011 2:07 pm
by Commander McLane
I think the best solution for this case is to move the escort immediately after spawning. That's how for instance the Sentinel Asteroids are positioned around a Hacker Outpost. It's done in the Hacker Outpost's ship script, and the steps are relatively straightforward:

Once your station exists, let it search for its escort. As soon as it has found the escort, change its position to whatever you want.

So what you basically need is the following in the station's script:

Code: Select all

this.shipSpawned = function()
{
    var myEscort = system.shipsWithPrimaryRole("myEscortRole")[0];
    myEscort.position = this.ship.position.add(this.ship.orientation.vectorForward().multiply(forward/backwardDistanceInMeters))
        .add(this.ship.orientation.vectorRight().multiply(right/leftDistanceInMeters))
        .add(this.ship.orientation.vectorUp().multiply(up/downDistanceInMeters));
}
I'm sure there is an easier way to write this, but it works. So if you want to place the escort 500 meters behind and 300 meters to the right of the station, simply insert the numbers -500 and 300 in the first two brackets and delete the last .add-part.

Re: Specifying escort postion

Posted: Mon Apr 11, 2011 2:15 pm
by Eric Walch
Smivs wrote:
Hi all,
Yet again my lack of understanding of js has reared it's head!
I want to place one escort in a specific position next to its Mother. After looking through the Wiki and BB I came up with this which is called from the mother's shipdata.plist

Code: Select all

this.coordinatesForEscortPosition = function ()
{
     this.EscortPosition(15, -80, 230);
}
which of course doesn't work. :roll:
help please!
you could try adding i the mothers ship-script:

Code: Select all

(function () {

this.coordinatesForEscortPosition = function (index)
{
    var position = Vector3D("your position here based on index")

    return position;
}

}).call(this);
On ship creation Oolite already adds the escorts on the intended escort position. When you really have one escort, you probably could ignore the index and always return (15, -80, 230). Better would be to make sure every value of "index" returns a different position.

Re: Specifying escort postion

Posted: Mon Apr 11, 2011 2:36 pm
by Smivs
Thanks.
I'll try both suggestions, and let you know how I got on.

Re: Specifying escort postion

Posted: Mon Apr 11, 2011 4:47 pm
by Thargoid
Or perhaps simpler to access the escort via this.ship.escorts to ensure that it's only the escort of the station that gets accessed. this.ship.escorts is an array of all the escorts that an entity has, so you can check the escort exists (this.ship.escorts.length > 0 or in this case === 1) and then access it as this.ship.escorts[0] again after checking that exists in the script sequence.

You can then set this.ship.escorts[0].position = [x,y,z] in the normal fashion as in McLane's suggestion above.

Re: Specifying escort postion

Posted: Mon Apr 11, 2011 6:24 pm
by Eric Walch
Thargoid wrote:
Or perhaps simpler to access the escort via this.ship.escorts to ensure that it's only the escort of the station that gets accessed.
That is probably the best. And also the complex calculations with vectorUp etc can be replaced by a single rotation:

Code: Select all

this.shipSpawned = function()
{
    this.ship.escorts[0].position = this.ship.position.add(Vector3D(15, -80, 230).rotateBy(this.ship.orientation));
}
That looks already much friendlier. Only rotateBy had a bug in older Oolite versions, so that it only works correct since Oolite 1.75

Re: Specifying escort postion

Posted: Mon Apr 11, 2011 6:50 pm
by Smivs
I've just done a quick test and that seems to be working.
Thanks guys :D

Re: Specifying escort postion

Posted: Mon Apr 11, 2011 7:49 pm
by Commander McLane
Eric Walch wrote:
Thargoid wrote:
Or perhaps simpler to access the escort via this.ship.escorts to ensure that it's only the escort of the station that gets accessed.
That is probably the best. And also the complex calculations with vectorUp etc can be replaced by a single rotation:

Code: Select all

this.shipSpawned = function()
{
    this.ship.escorts[0].position = this.ship.position.add(Vector3D(15, -80, 230).rotateBy(this.ship.orientation));
}
That looks already much friendlier. Only rotateBy had a bug in older Oolite versions, so that it only works correct since Oolite 1.75
I knew there must have been a simpler method than my complicated mess. :D