Jump to content

Query on Center of Mass and thrustTransforms in Unity


Recommended Posts

Silly question most likely but...

Is the Center of Mass in KSP calculated by model shape or is it pulled from the mesh that was setup in Unity?

To clarify, if needed, if I have just a bar and set the CoM of it to one end __________ ^ with the Y pointing up like in the silly text, will it fly straight or spin out of control? The CoM is perfectly inline with the thrustTransform.

Asking because I have a model that does that but not sure where the error lies. CoM of the model is close (I thought). Unity is set correctly about 0 for thrustTransform, yet the ship spins out of control with even the slightest acceleration.

Link to comment
Share on other sites

The center of mass is located at the root game object, so it's done in Unity. You can, if you know how to, calculate the center of mass of an object in Blender, and then place the root object at that location relative to the mesh, but IIR that function treats models as solid objects. It's a good enough approximation though.

The bar in your example is likely to spin around in weird ways, a bit like the stock landing legs do.

I usually set my mesh origin to be at the center of mass of the object in Blender so I can place the mesh at 0,0,0 of the root game object in unity.

Link to comment
Share on other sites

Trouble is, I've always set the CoM at 0,0,0 in Blender. The models are oddly shaped so I create a box, move to 0,0,0. Join the meshes to it and them break the connection.

That assinine 'click here to set the cursor' (a million miles away sometimes) is useless (to me at least). Why the heck is there no 'Set origin to 0' feature.

/rant off

But it seems not to matter what the heck I do in Blender. Unity moves the centers and, when creating a new 'gameobject' for say, thrustTransforms, it's not at Zero or close to the parent objects coords. Moving it to 0,0,0 sets it at odd locations.

About to give up and stick to a simple cylinder. Seems that's all I'm getting correct lately.

Edited by MLWostal
Link to comment
Share on other sites

Trouble is, I've always set the CoM at 0,0,0 in Blender. The models are oddly shaped so I create a box, move to 0,0,0. Join the meshes to it and them break the connection.

I don't know what this means.

That assinine 'click here to set the cursor' (a million miles away sometimes) is useless (to me at least). Why the heck is there no 'Set origin to 0' feature.

/rant off

Again I'm not sure what you're getting at here. The tool shelf has a number of options for setting the origin and the cursor dialogue can, among other things, move the cursor to 0,0,0 in global space.

But it seems not to matter what the heck I do in Blender. Unity moves the centers and, when creating a new 'gameobject' for say, thrustTransforms, it's not at Zero or close to the parent objects coords. Moving it to 0,0,0 sets it at odd locations.

About to give up and stick to a simple cylinder. Seems that's all I'm getting correct lately.

Each object in the hierarchy has a position in relation to its parent. The root empty game object (the one where you add parttools) can be anywhere, but the child objects of it have to be in specific places. If you set the origin of your mesh objects correctly in Blender, then childing them in Unity and moving their relative position to 0,0,0 will put them in the right place.

Link to comment
Share on other sites

I do apologize. My frustration level with learning Blender and Unity is showing and I should not have let it slip through my question.

I created a object composed of a number of meshes. They are individual to keep the poly count down for collision boxes in Unity, but share a only a few textures. That also means that there are a lot of Center of Masses. I've tried to use the cursor object and set CoM at cursor location but is difficult to me. If I'm not clicking on an object, the cursor object (forget what it's called, sorry) seems to never be where I want it. Usually, it's meters below and to the side of the actual 0,0,0 location.

To deal with that, I create a box, move it to 0,0,0 for CoM and then join the object I've created to it. This effectively sets its CoM to 0,0,0 as well. Or, so I though.

When I load my object into Unity, it puts the CoM within the individual objects again and forces me to 'quess' as to the correct location to balance thrust. On top of that, when I create a 'gameobject' empty container and child it to anything, it is not inheriting the parents location. It is offset by some amount and moving it, either by mouse or by pasting numbers, it does not seem to line up correctly. Under thrust in KSP, the objects spin uncontrollably.

I know the issue is with me. How I'm doing it, that is. I just don't know where I'm going wrong. Blender is new to me, just about a month or so using it but I'm not new to 3d modeling, started in 1985 :) I'm just looking for ideas or thoughts from the more experienced Blender users and did not mean to confuse or irritate anyone. trueSpace, the last 3d software I used, had a simple 'Set Axis' command. You just clicked the option and moved/set the objects origin to where ever you wanted it. I have not found that option in Blender and I have looked. But, I am not perfect and may have missed it.

Link to comment
Share on other sites

I created a object composed of a number of meshes. They are individual to keep the poly count down for collision boxes in Unity, but share a only a few textures. That also means that there are a lot of Center of Masses.

I can't help you if you don't use correct terms. This statement doesn't make sense. I think you're confused about what objects are.

Link to comment
Share on other sites

I'm more interested in helping you than I am in thinly veiled insults. If you want to convey meaning, then use correct words. I'm not a mind reader and spending time trying to interpret what you're saying is beyond acceptable to me. I'm doing all of this for free and not asking for anything except a little clarity in your only method of communication.

Link to comment
Share on other sites

Hopefully, the following pic will clear up my terms.

i225qs.jpg

If I group all the individual meshes (my term) into just one and load into Unity, it works but it is a static file. No animations will work this way or at least none that I can make.

In Unity 4.6.., the version I was using until recently due to my need for emissives, adding a gameobject always put the empty structure below the currently selected object. Say for example in the pic above, adding a thrustTransform to the engine nozzle. The thrustTransform would be centered exactly where the parent 'nozzle' was.

Now, using Unity 4.2.2, again, for emissives, the gameobject does not take the parents information. Instead, it is created at the root of the hierarchy structure and I must move it down manually to the correct location to be a child of the parent structure. This moving seems to be causing an issue as now, the gameobject must be changed to match the parent and in doing so, seems to offset the gameobject. In the case above (forgive the bad textures and subject matter please) the thrustTransform I would create just behind the Nozzle would infact cause the ship to spin uncontrollably. This is after setting every object not animated to have a '0,0,0' location.

I am at a loss as to what I am doing wrong and any help would be greatly appreciated. I also hope this clears up at least some of the

Edited by MLWostal
Link to comment
Share on other sites

Is the spaceship meant to be available in the VAB as a single, combined "part"? If so, you can define multiple animations in Blender, configure them in Unity, and then use a plugin like Firespitter to toggle each animation independently (the stock animation module can only support one persistent animation per part).

Assuming you're going for the "ship as one part" route, I suggest making the entire ship's CoM at 0,0,0 and aligning the thrust transforms along the appropriate axis:

1) Press Shift-S to open up the snap menu, and Select Cursor to Center

2) For each mesh, move it to the desired position, and then permanently afix it relative to 0,0,0 (Crtl-A > Location -and- Ctrl-A > Rotation & Scale)

When you re-import your one-piece spaceship into Unity, all the meshes will be in the correct position relative to the new CoM of 0,0,0 and you should be able to add the thrustTransform without worrying about off-center thrust.

Link to comment
Share on other sites

Thank you for the information. I had no idea that 'Select cursor to Center' even existed. Much to learn about Blender. It's VERY different from the program (called Caligari and trueSpace) I have used for almost 20 years. Solid modeler and useless now-a-days.

So, Select cursor to Center and then Object, transform, then Origin to 3d Cursor will do what I have been fighting with.

The ship does have animations and I want to do emissives. Have not figured out how to do both on the same model/object/mesh/really not sure what it's called. So I can't just group all. There needs to be separate parts (I think) and because of that, Unity throws the center of mass off and the darned ship tumbles stern over bow, even on the lowest settings.

As a single entity in Unity, then the CoM stays and the ship works but not the way it should.

Animation for the Landing leg in the rear, animation for the thrust vector change and an emissive for the large nozzle on the stern. Am I asking one item (ship loaded as one part in the VAB) to do too much?

Link to comment
Share on other sites

As a single entity in Unity, then the CoM stays and the ship works but not the way it should.

Animation for the Landing leg in the rear, animation for the thrust vector change and an emissive for the large nozzle on the stern. Am I asking one item (ship loaded as one part in the VAB) to do too much?

Personally, not at all.

My FusTek Station Parts has a set of IACBM docking ports, each of which have three animations per part that can be controlled independently:

- One animation to rotate the docking fins between passive (X) and active (+) positions

- One animation to turn on/off the red & white docking lights (emissives plus actual light sources)

- One animation to show/hide a FusTek standard yellow-rimmed hatch (the IACBM usually fits directly over existing hatches on FusTek modules, but stock crew tanks don't have hatches on their ends, so a retrofit option is provided)

In your case, you can import each animation from Blender into Unity separately, save it as separate .anim files, and add each to the exported part's list of animations:

- The landing gear animation can use the stock ModuleLandingGear (if it has wheels) or ModuleLandingLeg (if not)

- Is the emissive for lighted windows, the engine glow, or a headlight?

- Is the thrust vector change a simple gimbal (in which case an animation is not even needed), or is it for VTOL?

Link to comment
Share on other sites

Export each animation as a separate animation...... um.... Lost me there. If the animation is created in blender, it's still exportable in Unity as an animation file?

The landing leg is just that. A simple landing pad that, if I ever figure out the way to do it, will be a hinged leg and spring to dampen the landing. But that can wait right now as I can't even get to a point where landing is feasible. :/

This is a steampunk ship I saw and wanted to try recreating it for KSP so it needs VTOL to actually work. I've gotten VTOL to work, barely, but crashing every time is getting old. :( The ship cartwheels no matter what I do to the thrustTransforms. That is why I asked how the CoM is set. If it's a single body in KSP, is it still using CoMs from all the individual parts in Unity/Blender or will the CoM for thrust be centerline to the engine.

The main engine is centerline and almost all of the ship can be joined in Blender as one but the landing leg cannot due to the animation. So, is Unity/KSP averaging the CoM of the entire ship between the main ship and the landing leg or will it take just the CoM I've set?

The VTOL will rotate slowly and line up with the main nozzle but Unity seem to keep throwing it off. Since the lineup for main thrust is at the end of the animation sequence, it's rather difficult to get to that stage to set it. I run the animation in the scene window and when it stops, then I set the thrustTransform for the main engine. Am I being an idiot and doing it all wrong?

Link to comment
Share on other sites

Export each animation as a separate animation...... um.... Lost me there. If the animation is created in blender, it's still exportable in Unity as an animation file?

Unity has an Animation editor to allow you to edit/save individual animation clips, which are stored as .anim files.

You would then add an Animation component to the root level of your one-part spaceship, and within it you list the .anim files that you want to later export to .MU along with the model itself.

This is a steampunk ship I saw and wanted to try recreating it for KSP so it needs VTOL to actually work.

I see.

VTOLs are IMHO tricky to make with stock parts, so I'd imagine it to be even worse for an integrated mod part.

I've gotten VTOL to work, barely, but crashing every time is getting old. :( The ship cartwheels no matter what I do to the thrustTransforms. That is why I asked how the CoM is set. If it's a single body in KSP, is it still using CoMs from all the individual parts in Unity/Blender or will the CoM for thrust be centerline to the engine.

The main engine is centerline and almost all of the ship can be joined in Blender as one but the landing leg cannot due to the animation. So, is Unity/KSP averaging the CoM of the entire ship between the main ship and the landing leg or will it take just the CoM I've set?

The VTOL will rotate slowly and line up with the main nozzle but Unity seem to keep throwing it off. Since the lineup for main thrust is at the end of the animation sequence, it's rather difficult to get to that stage to set it. I run the animation in the scene window and when it stops, then I set the thrustTransform for the main engine. Am I being an idiot and doing it all wrong?

Basically, for a single part (or in your case, your single part ship) KSP doesn't care how many submeshes you have or where they are located - it will always use Blender's global 0,0,0 as the CoM of the entire part (unless you fiddle with CoMOffset in the CFG, but that's another story).

Your off-center thrust issue has two possible causes:

- If the cartwheeling occurs during level flight, you haven't aligned the thrustTransform along the appropriate global axis

- If the cartwheeling occurs during takeoff, where you're rotating the thrustTransform via animation while the engine is throttled up, then of course it will flip over because of unbalanced thrust:



+ is craft CoM
< and ^ are thrustTransform / rocket nozzle orientations

( )
( )+-------<
( )

Nozzle is pointing at in line with CoM, spaceship flies level and forward

( )
( )+-------^
( )

Nozzle is not pointing at or in line with CoM, a moment is created around CoM, about which the spaceship will rotate and cartwheel

If the above is the case, then you will need to redesign your spaceship to have a front engine to offset the rotational moment caused by case 2.

Link to comment
Share on other sites

Oh, I expect it to pitch a little bit during the thrust rotation. But the silly thing does it at liftoff.

Your explanation of the anim files helps me a great deal. I have another ship, a Jupiter 2 model that I've made in 4 parts due to the animation needs. I used the 2 engine setup on it to prevent the pitch, one for lift the other for forward flight, but it can be cumbersome to fly. Now, I can go back and even correct that thing though it does work perfectly as is, a simpler design would be nice. :) Thank you for that.

I've not even seen anyway to create a true VTOL using stock parts but yeah, VTOLs are tricky to balance.

The issue I'm having MUST be coming from Unity and some screwup I've done. Going to try again, starting from scratch, and see if works correctly or at least better, this time.

Link to comment
Share on other sites

If you want all your legs to have suspensions they will need to be separate parts. It's a KSP limitation.

About "Objects". Everything you can select separately in Blender in object mode is an object. Meshes in edit mode are called meshes even if they're not connected. An object can have one or more separate meshes. Other things like empties and lights and cameras are also objects. The same terminology applies in Unity

Edited by Cpt. Kipard
Link to comment
Share on other sites

Ah, I see the confusion. I always thought the full output, the entire finished model, was the Object. The individual parts in the modeling software was just a mesh and nothing more. Self-taught has some major disadvantages.

The landing leg, for the present, will be static. Just sitting there until all the other issues are sorted out. The reference pic I'm using to create the model appears to have 2 types of springs, no pistons. One on the geared section and on on the actual foot pad. Hope that's doable. If not, then just a single spring will have to do.

And thanks for not calling me a total idiot. I'm only mostly there so there is hope for me. :/

Link to comment
Share on other sites

Okay, you were right. VTOL is NOT easy, especially for a novice like myself with Unity.

Back to the drawing boards but, if anything, this has all taught me much more about Blender and Unity.

Now, if I could just understand groups in blender, animations might be easier. Oh well, back to the Blender app :)

Does KSP and or Unity support Parent/child and Groups?

Animating each individual component is rather bothersome at times. trueSpace had a hierarchical setup to joined items. IE, you could join as one but still access all submeshes. Seems parent/child does the same thing (kinda) and wonder how KSP likes it.

Edited by MLWostal
Link to comment
Share on other sites

I've never had to use or even encountered "groups". Blender supports hierarchical relationships too, and you can even import them into Unity but I do all of that in Unity unless an animation is involved.

I'm assuming you want an object to animate a set of other objects? If that's it then select the object you want as the child, then select the one you want as the parent and press Ctrl+P and choose an option. I tend to go with "keep transform". You do that for each individual relationship.

There's no grouping of which I'm aware but you can select more then one potential child, one by one, and finally the potential parent, and press Ctrl+P. Those relationships are still individual, it's just that you made them all at once.

Link to comment
Share on other sites

Thanks. The more I use Blender, the more I find in common with trueSpace, just it's done/called differently. That is most of my issue. As you pointed out earlier, proper names, and Blender changed them all on me. :)

The animation is rather complicated and parent/child seems the way to go for now.

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