Jump to content

[SOLVED] Modifying part.attachJoint.Joint.anchor


Recommended Posts

Ran into a weird problem when modifying a partJoint.

//Inside of a method
Vector3 v = new Vector3(0,0.6f,0);

Vector3 temp_0 = p_0pos + v;
Vector3 temp_1 = p_1pos + v;

p_0.attachJoint.Joint.anchor = temp_0;
p_1.attachJoint.Joint.anchor = temp_1;

That method is called from a gui event and it works really well, just as expected.

However, I thought the anchor position would be persistent, but it's not. OK no big deal, I can just write a Vector3 to a persistent string. Problem is
when I try to update the Joint.anchor from OnStart() it throws a null ref exception. Running same code from inside FixedUpdate will work, but one
can see the part move into place as the state is set. Obviously not desirable.

I'm rather stuck. Anyone have any clue how I can save the state of the anchor? 

Edited by Bonus Eventus
Link to comment
Share on other sites

On 11/10/2016 at 4:53 AM, sarbian said:

You should do your joint config when the onPartJointSet GameEvent is triggered.

Excellent, had a feeling you would know :)

EDIT:
The GameEvent onPartJointSet fires and the state is set as expected. Unfortunately, it fires around the end of the first update frame.
Nothing I can do about that. Wondering how vessels save positional data in sfs. There must be a way to alter the joint placement
onSave, otherwise how does KJR or IR keep state?

UDATE:
I experimented with overwriting the config for the part, but apparently that's not where the vessel data is being loaded from. Wised up,
now poking around in ShipConstruct and ShipConstruction. 

UPDATE2:
I found this post in "Help a fellow plugin dev" 

Thanks to IgorZ I was able to overwrite the Part>Position node of the sfs file with onProtoPartSnapShot which is an event fired for each part of a vessel when vessel.BackupVessel() is called.
So, the bottom line is, you can move physically simulated parts around (and all of their children) by animating or changing the vector3 of an attachJoint.Joint.anchor, and then save state by
injecting code after BackupVessel is finished saving. Only caveat is that iva does not move with the part when the anchor is update. Not a big deal, since you can find out easily which parts
of the children have an IVA and then move them.

Edited by Bonus Eventus
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...