Jump to content

Teleport to location


Recommended Posts

I am making a tool that edits a quicksave and teleports a vessel from the KSC runway to the Baikerbanur grass strip and I'm turning it into a proper KSP plug-in.  I'm almost there [first mod in <24 hours!?] but am bashing my head on one thing long enough to call in help.

The vessel is going to go from "landed on the KSC runway" to "landed at Baikerbanur", which really simplifies the deal.  I have a target lon, lat, alt and a workable attitude quaternion ("rot").

vessel.SetRotation(...) works.  I'm guessing I need an instance method such as SetPosition to change the surface location.  I'm not working in (x,y,z) but in (lon,lat,alt).  A pointer to some open source code that does this the simple and recommended way would be enough to break me loose, I think.  (I've been able to get the vessel to go from 69m to 422m (the target altitude at BKB) and to rotate attitude, but lon/lat won't budge when I set them directly via the Vessel fields.)

I can convert lon/lat to Cartesian if I have to.  And in the absence of advice, I guess I can check what the (x,y,z) for KSC looks like...

---

One unrelated question is that I am posting status messages to the screen to the user.  I'd like the error messages in a different color from the standard off-green.  I've seen there is a kind of standard orange in use: e.g. solar panels broken by aero forces.  Cannot see anything in the classes for this.   (I've been using this site, http://kspapi.forwoods.org/#/classes/ScreenMessages,  for documentation because I cannot find any official documentation for 1.3.1.  Some sites I've found just come up with mostly blank pages...??)

Any help would be really appreciated.

Edited by Hotel26
Link to comment
Share on other sites

This looks promising:

        CelestialBody body = vessel.mainBody;
        vessel.SetPosition(body.GetWorldSurfacePosition(lat2, lng2, alt2 + hgt));

and indeed, it momentarily makes me appear over some ocean...  I wonder if I have to call something to notify KSP that the ActiveVessel has effectively "changed scene"...?

 

Link to comment
Share on other sites

1 minute ago, SpannerMonkey(smce) said:

As done by Kerbal Konstructs  for years and now Squad

Ger_space recommended that I use Kerbal Konstructs, too.  I took a look at it and it looks like a pretty big and capable mod.  Are you associated with that mod, by chance; i.e. as an author or maintainer?

When you say, "now Squad", I'm guessing you mean 1.4?

Link to comment
Share on other sites

1 hour ago, Hotel26 said:

When you say, "now Squad", I'm guessing you mean 1.4?

Yes.
HI, no , no direct association other than occasional contributor, fan and user since it was kerbtown.
Not even suggesting that you not do your thing, just that in some way at least the problem has been solved a couple of times already. 

Another one sprung to mind, and one that is free to modify and use with  credit, Firespitter has a launch to water or wherever facility, a bit broken right now it seems but it definitely still move craft around . That can be found here https://github.com/snjo/Firespitter/search?utf8=✓&q=water+launch&type=

 

Link to comment
Share on other sites

16 hours ago, SpannerMonkey(smce) said:

Not even suggesting that you not do your thing, just that in some way at least the problem has been solved a couple of times already. 

Thank you for that as it does ease my mind!  And I am glad you and Ger_space brought Kerbal Konstructs to my attention.  I do have strong reasons for making this mod I am working on.

I'll be announcing the next release of my "add-on" as a bona fide KSP plug-in shortly and I will be very happy to put in a plug for Kerbal Konstructs, in that announcement, and recommend that potential down-loaders familiarize themselves with its capabilities at the same time.  I think KK is a pretty fine contribution to the KSP community and I commend you guys for bearing a large commitment in maintaining/testing it.

 

Link to comment
Share on other sites

  • 4 weeks later...

I am very, very close but still requesting assistance.

I can teleport once with no problem.  Subsequent teleports encounter a shaking that occurs on all craft in the neighborhood but ceases once I have changed focus away and back as shown in the following video:

The log shows an error reported by RasterPropMonitorComputer presumably provoked by some error on my part.  The vessel contains a crew member, but I have done nothing in particular with regard to it.

[LOG 15:14:37.255] Unpacking Aeris 3A
[LOG 15:14:40.509] Packing Aeris 3A for orbit
[LOG 15:14:40.511] Telemagic:  teleported to Baikerbanur 20.6 -146.6 423
[LOG 15:14:40.561] [Aeris 3A]: landed - waiting for ground contact to resume physics...
[ERR 15:14:40.564] [RasterPropMonitorComputer]: UpdateLocalCrew() - no internal model!
[LOG 15:14:41.596] [FlightIntegrator]: Reloaded drag cube for zeroed cube root part Mark1Cockpit (Aeris 3A) on vessel Aeris 3A
[LOG 15:14:41.596] [FlightIntegrator]: Vessel Aeris 3A has been unloaded 9.75999999999112, applying analytic temperature 301.749351045848
[LOG 15:14:44.651] Unpacking Aeris 3A
[LOG 15:14:44.681] [Aeris 3A]: ground contact! - error. Moving Vessel  down -0.230m
[LOG 15:14:44.681] Unpacking Aeris 3A
[LOG 15:14:49.191] [UIMasterController]: ShowUI

The code sequence I use is:

        CelestialBody body = vessel.mainBody;
        
        var telePos = body.GetWorldSurfacePosition(lat2, lng2, alt2 + hgt) - body.position;
        var teleVel = Vector3d.Cross(body.angularVelocity, telePos);

        // convert from world space to orbit space
        telePos = telePos.xzy;
        teleVel = teleVel.xzy;
        // counter for the momentary fall when on rails (about one second)
        teleVel += telePos.normalized * (body.gravParameter / telePos.sqrMagnitude);

        var orbit = Clone(vessel.orbitDriver.orbit);
        orbit.UpdateFromStateVectors(telePos, teleVel, body, Planetarium.GetUniversalTime());

        vessel.Landed = false;

        var oldUp = vessel.orbit.pos.xzy.normalized;
        var newUp = telePos.xzy.normalized;
        qrot = Quaternion.FromToRotation(oldUp, newUp) * vessel.vesselTransform.rotation;

        SetOrbit(vessel, orbit);
        vessel.SetRotation(qrot);   // mult2(qrot, rot) [TM]

 

Can anyone throw any light on this, please?

 

Link to comment
Share on other sites

4 hours ago, Hotel26 said:

Can anyone throw any light on this, please?

The error occurs when RPM tries to update crew information on a pod that does not have an IVA.  According to the comments I left myself in that code, this is something that can happen sometimes on spawn.  If the error does not keep repeating in the log, it's safe to ignore.

Link to comment
Share on other sites

  • 2 weeks later...

For anyone interested in this topic, there is a class called VesselTeleporter in the latest KSP API.  I'm working in 1.3.1, so I am assuming it may be a new class.

(Although, be advised, it inherits from EditorWindow and may be predicated upon deployment from an Assembly Building.)

 

Edited by Hotel26
Link to comment
Share on other sites

  • 2 months later...
On 5/6/2018 at 8:42 AM, Hotel26 said:

For anyone interested in this topic, there is a class called VesselTeleporter in the latest KSP API.  I'm working in 1.3.1, so I am assuming it may be a new class.

(Although, be advised, it inherits from EditorWindow and may be predicated upon deployment from an Assembly Building.)

 

I see that class in the api (https://kerbalspaceprogram.com/api/class_vessel_teleporter.html#adf79a0a401fd2d6512111f68a448e93d) but I can't use it even in 1.4.4
I'm also interested in this as with LMP I'm having issues when moving a vessel that is on physics range (unpacked)

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...