player.ship.spawn spawns objects too close to the ship

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
Screet
---- E L I T E ----
---- E L I T E ----
Posts: 1883
Joined: Wed Dec 10, 2008 3:02 am
Location: Bremen, Germany

player.ship.spawn spawns objects too close to the ship

Post by Screet »

Hi,

using the trunk version, I regularly have crashes with the released objects when a script uses the spawn method. Could it be that the spawn routine does not include a safe-distance and also ignores the flightpath of the ship, thus sometimes spawning the objects so that they cause instant collisions?

It happens very often with the guardian drones (launched and destroyed in the same moment) and my modified auto-chaff-release.

Screet
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: player.ship.spawn spawns objects too close to the ship

Post by Eric Walch »

Screet wrote:
I regularly have crashes with the released objects when a script uses the spawn method. Could it be that the spawn routine does not include a safe-distance and also ignores the flightpath of the ship, thus sometimes spawning the objects so that they cause instant collisions?
It does spawn ships very close by. (Also older oolites) Try spawning a very big ship and you notice you are sometimes partly within. But when standing still while spawning I never had a crash with the object. Just wait until the other ship has moved away before starting to fly again.
User avatar
Frame
---- E L I T E ----
---- E L I T E ----
Posts: 1477
Joined: Fri Mar 30, 2007 8:32 am
Location: Witchspace

Post by Frame »

it spawns within your ships collision radius, which is calculated in such a fashion using averages of length/width and height of the ship it is spawned at,so it will sometimes spawn in such a manner that you collide with it, or as Erich wrote: Within it.....

its best to spawn other ships when not moving. while smaller objects such as missiles sized objects tend to have a better chance of getting away from the collision area...

This is not a new thing, when I originally wrote the Rock Hermit Locator* for Oolite 1.65, it spawned buoys close to asteroids... but almost never within them...

*Eric Walch wrote the version for Java scripting, taking over development of the RTL with my permission...

Cheers Frame...
Last edited by Frame on Sun May 24, 2009 12:49 pm, edited 1 time in total.
Bounty Scanner
Number 935
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

I think spawn was originally mend to be used to add objects in a death action to replace the original. Therefor it is probably deliberate it adds the stuff so close.
It happens very often with the guardian drones (launched and destroyed in the same moment) and my modified auto-chaff-release.
The drones should probably not be added with a spawn() but with a addShipsAtPrecisely() and than under the ship so you don't hit it.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

Eric Walch wrote:
The drones should probably not be added with a spawn() but with a addShipsAtPrecisely() and than under the ship so you don't hit it.
Now there's a good idea. Although I can't use precisely as sometimes we're spawning two of them. But within radius centred around a point below the player ship would work.
Screet
---- E L I T E ----
---- E L I T E ----
Posts: 1883
Joined: Wed Dec 10, 2008 3:02 am
Location: Bremen, Germany

Post by Screet »

Thargoid wrote:
Eric Walch wrote:
The drones should probably not be added with a spawn() but with a addShipsAtPrecisely() and than under the ship so you don't hit it.
Now there's a good idea. Although I can't use precisely as sometimes we're spawning two of them. But within radius centred around a point below the player ship would work.
I could use such a code myself for something I'm working on ;)

However, I do wonder if this indicates that Oolite should provide an easy way for this itself, instead of requiring scripts to take this problem into account and handle it themselves. If there are other oxp's which could use a safe spawning, maybe there should be such a method.

Screet
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

Screet wrote:
However, I do wonder if this indicates that Oolite should provide an easy way for this itself, instead of requiring scripts to take this problem into account and handle it themselves. If there are other oxp's which could use a safe spawning, maybe there should be such a method.
The nice thing of spawn() is that it returns the entity (or array of entities) that you can manipulate afterwards. Like Thargoid does with the sledges of the hammerhead.

An other save method of adding small stuff nearby the ship is using the ejectItem() command. (or ejectSpecificItem() )This adds stuff at a save distance behind the ship. Only drawback of ejectItem is that it always sets scannClass to CLASS_CARGO. This because it uses a function that originally only was mend for ejecting the cargopods.

In case of the guardians you are hitting against, the scann_class is now ROCK. When changing it to CARGO, the player won't see a difference. And to make them unscoopable, define a key inside shipdata of cargo_type = CARGO_NOT_CARGO; Ejecting the guardians is may even look more natural than just spawning.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

My plan is to change the spawning from just a simple player.ship.spawn to

Code: Select all

system.legacy_addShipsWithinRadius("aquatics_guardianPlayer", missionVariables.aquatics_guardianCount, "abs", player.ship.position.subtract(player.ship.orientation.vectorUp().multiply(20)), 10);
Basically spawning them below the ship, in a 10m sphere centred 20m underneath the ship. So there is enough gap for avoidance I think.

You are right that it may look better to have the ship launch the drones rather than have them just appear below the ship (but as the guardians here are player equipment, who is generally going to see it?). My only concern would be that if the players target is in front of the ship, the drones may try and fly directly through the player ship to reach it. And I think it's more likely that the target is directly in front than directly above.

Plus I guess if there are two guardians spawned (the default number intiially) there is the risk of them hitting one another?
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

Thargoid wrote:
You are right that it may look better to have the ship launch the drones rather than have them just appear below the ship (but as the guardians here are player equipment, who is generally going to see it?). My only concern would be that if the players target is in front of the ship, the drones may try and fly directly through the player ship to reach it. And I think it's more likely that the target is directly in front than directly above.
I just played with the code and the guardians work well. I just replaced in aquatics_equipment.js the line:

Code: Select all

player.ship.spawn("aquatics_guardianPlayer", missionVariables.aquatics_guardianCount);
by the line

Code: Select all

for(var i=0; i < missionVariables.aquatics_guardianCount; i++) player.ship.ejectItem("aquatics_guardianPlayer")
Now the drones appear at the back of the ship. For testing purposed I put the drone-count at four. In a few test launches I never saw a crash. An yes because of their backwards velocity it takes them a bit longer to arrive at the target. And when looking backwards or with the side-view option, you see the launch clearly.
Post Reply