Starstrider42 / Custom-Asteroids

A KSP mod that lets users control where asteroids appear
http://starstrider42.github.io/Custom-Asteroids/
MIT License
13 stars 10 forks source link

CustomAsteroidPlanes does not transform consistently #26

Closed Starstrider42 closed 8 years ago

Starstrider42 commented 8 years ago

Background Info

I've found a weird bug that slipped through my testing of inclined asteroid groups. All behaviour in this post was tested by replacing the Custom Asteroids config that ships with RSS with this file.

If I load KSP and start a new game, asteroids will be aligned with the orbital planes of the RSS. Edge-on view: Oblique view:

However, if I either:

then newly spawned asteroids will no longer have the correct orbital orientation, so long as I spawned at least one asteroid. Sometimes the effect is a few degrees, sometimes it's dozens. Oblique view of a bad case:

Within a KSP session and for a single save game, the orbital orientation does not change. I've yet to find a way of predicting the size of the offset; I used to think it increased with the number of asteroids spawned previously, but that's not the case. The rotation does not appear to be around a special axis.

Technical Details

The orbit rotations done by CustomAsteroidPlanes are implemented by finding the asteroid's untransformed state vectors (using Orbit.getRelativePositionAtUT(ut) and Orbit.getOrbitalVelocityAtUT(ut)), left-multiplying them by a Quaternion, and calling Orbit.UpdateFromStateVectors with the altered vectors. I've added some debugging logs, and the transformer swears it's always doing the same transformation, regardless of what the map view looks like:

Calibration: [0, 0, 1] -> [0.026371156796813, -0.390285193920136, 0.920316278934479] Calibration: [1, 0, 0] -> [0.999589502811432, -1.84732489287853E-05, -0.0286505203694105] Calibration: [0, 1, 0] -> [0.0111988745629787, 0.92069399356842, 0.390124499797821]

Starstrider42 commented 8 years ago

Just confirmed that this bug can be reproduced without either Kopernicus or RealSolarSystem: screenshot11