Jump to content

Centre of Mass


Recommended Posts

Hi

I'm having some trouble reading the centre of mass of a vessel. It always gets returned as (0, 0, 0).

I can't quite figure out what position it should return relative to, but part.orgPos always gets returned in relation to the root part, so I assumed it would be similar to that.


Vector3 thisVesselCoM = this.part.vessel.CoM;

Have I completely lost the plot? Any insights would be appreciated - I'm trying to figure out a parts position relative to the CoM.

Managed to figure most things out now, but this has got me stumped.

Cheers and thanks in advance :)

Link to comment
Share on other sites

Two possible problems:

1 - Are you taking the reading while the vessel is on rails? If so it won't work and you just get a hardcoded (0,0,0) answer.

2 - Are you taking the reading immediately after the vessel comes off of rails? If so then (0,0,0) is actually the correct answer. When the vessel first comes off of rails KSP builds the Unity world using a reference frame centered right where the vessel CoM is. After the physics sim has been running a few minutes, you will then see that the ship has drifted away from the origin.

Link to comment
Share on other sites

Aha, that would explain it. It's in the OnStart override so yes and no. I'll have to use a different method but the sound of it.

Thank you, I'll run some further testing :)

Link to comment
Share on other sites

If the world coordinates are currently centered on the CoM then it should work fine - the coordinates of anything else will be returned relative to that.

What are you actually trying to find out? The location of ___ relative to ___? Fill in the blanks and I can give suggestions.

Link to comment
Share on other sites

Sorry, I've been so busy coding I've not updated the thread. So, a more full explanation:

I'm working with wheels and I want to find the wheels position relative to the vessel CoM to calculate how much it should steer. Wheels further from the CoM should turn the full amount, wheels close to it should turn proportionally less. I've figured out a way to do it simply using the length of the wheelbase, but being relative to CoM would be the icing on the cake. My dev thread is http://forum.kerbalspaceprogram.com/threads/84102-WIP-PARTS-PLUGIN-Kerbal-Foundries-wheelpack-anti-grav-repulsors so you can see what I'm doing.

I've been poking around at what I can call from this.vessel, though the world co-ord from .CoM doesn't seem to help here, unless there's some way of inverting it to co-ords local to the vessel?

Thanks for your time, appreciate it!

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