Closed PhilouDS closed 4 months ago
I think the problem is that neither your plane nor the surface position is fixed in time. The only global fix point is Kerbol (and maybe even that will change with interstellar?). So if you move
const landing_point = vessel.main_body.global_surface_position(-0.63, -75.02, landing_height)
into the while loop it should work.
Here is a more compact version, I tested with a rover:
use { Vessel } from ksp::vessel
use { CONSOLE, RED, WHITE } from ksp::console
use { sleep } from ksp::game
use { DEBUG } from ksp::debug
pub fn main_flight(vessel: Vessel) -> Result<Unit, string> = {
const geo = vessel.main_body.geo_coordinates(-0.64, -75.02)
DEBUG.clear_markers()
DEBUG.add_billboard(fn() -> vessel.global_position + 15 * vessel.global_facing.right_vector,
fn() -> $"Lat: {vessel.geo_coordinates.latitude:N3}\nLon: {vessel.geo_coordinates.longitude:N3}", WHITE, 8)
DEBUG.add_vector(fn() -> vessel.global_position, fn() -> geo.global_altitude_position(geo.terrain_height + 100) - vessel.global_position, RED, "", 1)
sleep(100000)
}
Though I noticed that geo.global_altitude_position(geo.terrain_height)
is several meters below the ground, that's why the + 100
... there might be a bug in the .terrain_height
calculation.
Another alternative would be to do the calculation with normal vectors in the the main_body.body_frame
(i.e. the rotating reference frame of the planet):
use { Vessel } from ksp::vessel
use { CONSOLE, RED, WHITE } from ksp::console
use { sleep } from ksp::game
use { DEBUG } from ksp::debug
pub fn main_flight(vessel: Vessel) -> Result<Unit, string> = {
const body_frame = vessel.main_body.body_frame
const height = vessel.main_body.terrain_height(-0.64, -75.02)
const surf_pos = vessel.main_body.global_surface_position(-0.64, -75.02, height + 100).to_local(body_frame)
DEBUG.clear_markers()
DEBUG.add_vector(fn() -> vessel.global_position, fn() -> (surf_pos - vessel.global_position.to_local(body_frame)).to_global(body_frame), RED, "", 1)
sleep(100000)
}
Thank you. The first script works well. I used a while
loop because I didn't know that the vector was updated even without loop. That's great!
That is the reason why DEBUG.add_vector
takes callback functions as arguments and not just vectors.
The callbacks are run with every frame-update just before the actual 3D-line is added to the game-scene.
In 0.5.6.2 the terrain_height
should be correct.
Internally there is an additional scenery offset, which (I guess) is referring to Buildings etc.
This issue is stale because it has been open for 60 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
I tried to use
DEBUG.add_vector
to draw a vector from my plane to the runway. But I probably don't understand howGlobalPosition
andGlobalVector
work. I can't have what I want. Here is my code:My red vector is clearly not pointing at the runway! How should I do that please?