Specifying escort postion

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

Post Reply
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Specifying escort postion

Post 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!
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2272
Joined: Tue Jan 02, 2007 12:38 pm

Re: Specifying escort postion

Post 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
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Specifying escort postion

Post 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.
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: Specifying escort postion

Post 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.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Specifying escort postion

Post 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.
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Specifying escort postion

Post by Smivs »

Thanks.
I'll try both suggestions, and let you know how I got on.
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Specifying escort postion

Post 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.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Specifying escort postion

Post 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
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Specifying escort postion

Post by Smivs »

I've just done a quick test and that seems to be working.
Thanks guys :D
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: Specifying escort postion

Post 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
Post Reply