Jump to content

Spawning from a ProtoCrewMember


Recommended Posts

I'm trying to put a kerbal in the world given a ProtoCrewMember. Doing some cargo cult programming looking at what ContractConfigurator does, I came up with this:


ProtoCrewMember protocrew = [etc...]
var flight = ShipConstruction.GetUniqueFlightID(HighLogic.CurrentGame.flightState);
var crew = new ProtoCrewMember[1];
crew[0] = protocrew;
var parts = new ConfigNode[1];
parts[0] = ProtoVessel.CreatePartNode("kerbalEVA", flight, crew);
var nothing = new ConfigNode[0];
var orbit = new Orbit(0,0,0,0,0,0,0,vessel.mainBody);
var position = vessel.GetWorldPos3D();
orbit.UpdateFromStateVectors(position, vessel.mainBody.getRFrmVel(position), vessel.mainBody, Planetarium.GetUniversalTime());
var vesselConfig = ProtoVessel.CreateVesselNode(protocrew.name, VesselType.EVA, orbit, 0, parts, nothing);
var protoVessel = HighLogic.CurrentGame.AddVessel(vesselConfig);

Trying this from the launchpad, the result is always a message in the log "Vessel Jebediah Kerman crashed through terrain on Kerbin". I'm guessing that means something is wrong with the orbit I'm providing, or the position it is based on, but I don't see how that could be since they're constructed based on a vessel not crashing through terrain.

Link to comment
Share on other sites

Getting closer - I now have a landed kerbal. However, it doesn't seem to actually initialize gender, trait, or personality from the provided ProtoCrewMember.

Here's what I'm doing:

uint LetThereBeKerbal(ProtoCrewMember protocrew) {
var body = vessel.mainBody;
var flight = ShipConstruction.GetUniqueFlightID(HighLogic.CurrentGame.flightState);
var crew = new ProtoCrewMember[1];
crew[0] = protocrew;
var parts = new ConfigNode[1];
parts[0] = ProtoVessel.CreatePartNode("kerbalEVA", flight, crew);
var extra = new ConfigNode[0];
var orbit = Orbit.CreateRandomOrbitAround(body);
var vesselConfig = ProtoVessel.CreateVesselNode(protocrew.name, VesselType.EVA, orbit, 0, parts, extra);
var position = part.transform.position;
position += (position-body.position).normalized * 5.0;
vesselConfig.SetValue("sit", Vessel.Situations.LANDED.ToString());
vesselConfig.SetValue("landed", true.ToString());
vesselConfig.SetValue("lat", (body.GetLatitude(position)).ToString());
vesselConfig.SetValue("lon", (body.GetLongitude(position)).ToString());
vesselConfig.SetValue("alt", (body.GetAltitude(position)).ToString());
var protoVessel = HighLogic.CurrentGame.AddVessel(vesselConfig);
return flight;
}

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...