Jump to content

'thrustTransform' Wants to Point Sideways


Recommended Posts

Putting this general because it's related to both C# and 3d modelling, so I wasn't sure which one to put it in.

I'm working on an engine part with a custom gimbal module, and I'm having trouble with the thrustTransform.  For some reason, the thrustTransform points directly north when in the flight scene.  I have a rocket engine that is made of several .blend meshes.  I have double triple checked that the meshes in both Blender and Unity are aligned correctly, as you can see in the screenshots.  I have also deleted and re-created the blank axis mesh in 'thrustTransform.blend' several times, rotating it in various direction in case it got screwed up somehow.  I would just rotate the thrustTransform 90°, but then the custom gimbal points in the wrong direction - I can't get both the thrustTransform and the gimbal to point in the same direction.

I'm guessing that there's a problem with how the thrustTransform mesh is aligned in Blender, but I have spent nearly 24 hours now consulting with the wiki and ChatGPT, to no avail.

Screenshots:

Spoiler

jptuzVp.png
M591X5j.png
y8fHXfr.png

I'm not sure if it's helpful, but here is my module code, in case:

Spoiler
namespace ProceduralEngines
{
    internal class ModuleProceduralGimbal : PartModule
    {
        [KSPField(isPersistant = true, guiActiveEditor = true, guiName = "Include Gimbal"),
        UI_Toggle(scene = UI_Scene.Editor)]
        public Boolean includeGimbal = false;

        [KSPField(isPersistant = true, guiActiveEditor = true, guiName = "Gimbal Range", guiFormat = "F1", guiUnits = "°"),
        UI_FloatEdit(scene = UI_Scene.Editor, minValue = 0f, maxValue = 45.0f, incrementSlide = 1f, incrementLarge = 5f, incrementSmall = 0.5f, sigFigs = 2, unit = "°")]
        public float gimbalRange = 15f;

        [KSPField(isPersistant = true, guiActiveEditor = true, guiActive = true, guiName = "Gimbal Limit", guiFormat = "F1"),
        UI_FloatEdit(scene = UI_Scene.All, minValue = 0f, maxValue = 100.0f, incrementSlide = 1f, sigFigs = 0)]
        public float gimbalLimit = 100f;

        [KSPField]
        public Transform thrustTransform;

        public override void OnStart(StartState state)
        {
            base.OnStart(state);
        
            thrustTransform = part.FindModelTransform("thrustTransform");

            if (HighLogic.LoadedSceneIsFlight)
            {

            }
        }
        public void Update()
        {
        
            if (HighLogic.LoadedSceneIsEditor)
            {
                Fields["gimbalRange"].guiActiveEditor = includeGimbal;
                Fields["gimbalLimit"].guiActiveEditor = includeGimbal;
            }
            
            if (HighLogic.LoadedSceneIsFlight)
            {
                Fields["gimbalLimit"].guiActive = includeGimbal;
            }
            
            if (HighLogic.LoadedSceneIsFlight && thrustTransform != null && includeGimbal)
            {
                if (part.inverseStage == vessel.currentStage)
                {
                    float limitedRange = gimbalRange * 0.01f * gimbalLimit;
            
                    float pitchInput = vessel.ctrlState.pitch;
                    float rollInput = vessel.ctrlState.roll;
                    float yawInput = vessel.ctrlState.yaw;
            
                    float angleToSetPitch = Mathf.Clamp(pitchInput * limitedRange, -limitedRange, limitedRange);
                    float angleToSetRoll = Mathf.Clamp(rollInput * limitedRange, -limitedRange, limitedRange);
                    float angleToSetYaw = Mathf.Clamp(yawInput * limitedRange, -limitedRange, limitedRange);

                    thrustTransform.localRotation = Quaternion.Euler(angleToSetPitch, angleToSetRoll, angleToSetYaw);
                }
            }
        }
    }
}

 

 

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