Jump to content

Parts relative rotation an position to parent


Recommended Posts

Greetings! : D

I've been trying to figure out a method for measuring a crafts "wobbliness"/rigidity and have things happen when it's poorly constructed or subjected to excess stress. I've been looking into breaking forces and torque, but as I have understood, it is not possible to have Unity give up any values on forces applied to a part's joints, except when it has actually fallen off.

I was therefore thinking of trying to measure parts relative rotation and position to its parent part (or joint). Then store the values at start of a flight. Then during flight check the offset values of the original position/rotation. Then finally, have thing happen when the offset values are too great.

However, I've been trying for a while to figure out exactly what I should measure (or where I can get the information I need), but I'm still just as clueless as I was when I started.

Any help would be greatly appreciated : D

Link to comment
Share on other sites

Unity's different frame of references will help you here, specifically the LocalSpace reference.

WorldSpace is the absolute coordinates of the actual 3D game world, if a part moves 10 meters, it's position vector will have changed by 10 meters.

LocalSpace is relative to the part. (So yes, each part has it's own LocalSpace.) From your current part, get the zero location of it's parent part in LocalSpace and store it. As LocalSpace is relative to the part, any changes in this number mean the relative positions of the parts has changed that much.

Note that KSP has a couple odd quirks with frame of reference:

WorldSpace: While WorldSpace is absolute, it is also limited to the area immediately around the vessel as that is only the area of space being simulated by KSP. So WorldSpace coordinates are not persistent or consistent, don't rely on them.

ScaledSpace: Specific to KSP, this was added to calculate orbits as the numbers involved were getting so big that math overflow errors were occuring. I never worked with this and don't know any further details.

Hope that helps,

D.

Link to comment
Share on other sites

Part.orgRot may do about 90% of what you're trying to do. Something like this (note: only slightly verified Quat math...)

Quaternion rotError = part.transform.localRotation * part.orgRot.Inverse();

Should be able to tell you how much the part has deviated from it's original rotation

There's also a part.orgPos field that probably can be used the same way. Whether that is relative to it's parent or the vessel would determine how useful it is though

Vector3 locError = part.transform.localPosition - part.orgLoc;

 

Edited by Crzyrndm
Link to comment
Share on other sites

4 hours ago, Diazo said:

Unity's different frame of references will help you here, specifically the LocalSpace reference.

WorldSpace is the absolute coordinates of the actual 3D game world, if a part moves 10 meters, it's position vector will have changed by 10 meters.

LocalSpace is relative to the part. (So yes, each part has it's own LocalSpace.) From your current part, get the zero location of it's parent part in LocalSpace and store it. As LocalSpace is relative to the part, any changes in this number mean the relative positions of the parts has changed that much.

Note that KSP has a couple odd quirks with frame of reference:

WorldSpace: While WorldSpace is absolute, it is also limited to the area immediately around the vessel as that is only the area of space being simulated by KSP. So WorldSpace coordinates are not persistent or consistent, don't rely on them.

ScaledSpace: Specific to KSP, this was added to calculate orbits as the numbers involved were getting so big that math overflow errors were occuring. I never worked with this and don't know any further details.

Hope that helps,

D.

This helps a lot! It's a lot more complicated than I expected. Thanks! : D

 

1 hour ago, Crzyrndm said:

Part.orgRot may do about 90% of what you're trying to do. Something like this (note: only slightly verified Quat math...)


Quaternion rotError = part.transform.localRotation * part.orgRot.Inverse();

Should be able to tell you how much the part has deviated from it's original rotation

There's also a part.orgPos field that probably can be used the same way. Whether that is relative to it's parent or the vessel would determine how useful it is though


Vector3 locError = part.transform.localPosition - part.orgLoc;

 

Amazing! This seems to be exactly what I was looking for! Thanks! :D

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