Jump to content

[Resolved] Cockpit lights


Recommended Posts

Anyone know of a tutorial that shows how to do this in Unity? I've looked at Lack's 'pictures' and am left dumbfounded.

Do you mean inside the IVA? Or the windows on the outside?

For external windows, you'd have to set up an animated emissive. The emissives are pretty straightforward by themselves. You'd want to use either the KSP/Emissive->Diffuse or KSP/Emissive->Specular shader (depending on whether you're making it shiny or not), and the emissive texture can be a lower-resolution greyscale PNG that has the window parts of the texture closer to white, while the rest is black. Then you'd create an animation that alters the emissive color.

Link to comment
Share on other sites

Do you mean inside the IVA? Or the windows on the outside?

For external windows, you'd have to set up an animated emissive. The emissives are pretty straightforward by themselves. You'd want to use either the KSP/Emissive->Diffuse or KSP/Emissive->Specular shader (depending on whether you're making it shiny or not), and the emissive texture can be a lower-resolution greyscale PNG that has the window parts of the texture closer to white, while the rest is black. Then you'd create an animation that alters the emissive color.

You guessed correct. The process, I sorta figured out. I made the texture, set the emissive and then got stumped. Setting up the animation, where to place it in the hierarchy, do I add a new object and drop it there or add it to my main mesh, etc.

Link to comment
Share on other sites

You guessed correct. The process, I sorta figured out. I made the texture, set the emissive and then got stumped. Setting up the animation, where to place it in the hierarchy, do I add a new object and drop it there or add it to my main mesh, etc.

You can create the animation in the top level game object for the part. It doesn't need its own game-object, and you want the part's meshes/etc to be children under where you define it, so the top is usually good. And then take note of whatever name you give it, to use in the part's CFG.

Link to comment
Share on other sites

So I could add it to the same object that holds parttools for example? Or one under that?

Yep, with the part tools is fine. You can "Add Component", and under "Misc" you'll find "Animation" (not "Animator"). Go to Window->Animation to open up the animator timeline. In there you can start a new clip, and drill down into your materials and add curves to the emissive colors.

Link to comment
Share on other sites

Ok, here's what I did. I created my animation and it looks like the screenshot below. I decided to attempt to play with the opacity of the emissive. I added this to my .cfg file

	
MODULE
{
name = ModuleAnimateGeneric
animationName = BridgeLights
actionGUIName = Toggle Lights
startEventGUIName = Lights On
endEventGUIName = Lights Off
}

and... it won't even load the part in KSP.

Here's the error log'

Load(Model): Maritime Testing/Cargo Bridge/model

(Filename: C:/buildslave/unity/build/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 56)

File error:
(null)
at (wrapper managed-to-native) UnityEngine.AnimationClip:SetCurve (string,System.Type,string,UnityEngine.AnimationCurve)

at A..ReadAnimation (System.IO.BinaryReader br, UnityEngine.GameObject o) [0x00000] in <filename unknown>:0

at A..ReadChild (System.IO.BinaryReader br, UnityEngine.Transform parent) [0x00000] in <filename unknown>:0

at A..ReadChild (System.IO.BinaryReader br, UnityEngine.Transform parent) [0x00000] in <filename unknown>:0

at A.. (.UrlFile ) [0x00000] in <filename unknown>:0

(Filename: C:/buildslave/unity/build/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 56)

Model load error in 'E:\Kerbals 103 Basic\GameData\Maritime Testing\Cargo Bridge\model.mu'

So what did I do wrong to create this mess?

-edit- And thinking opacity might be something I shouldn't tinker with (though I can't imagine why) I swiched to the emissive color and same error. I also found this thread by nil which lists the exact error. So, went in and made some more keys to give them 'curves'.. same error.

windows1.jpg

Edited by Fengist
Link to comment
Share on other sites

Here's the error log'

-snip-

So what did I do wrong to create this mess?

-edit- And thinking opacity might be something I shouldn't tinker with (though I can't imagine why) I swiched to the emissive color and same error. I also found this thread by nil which lists the exact error. So, went in and made some more keys to give them 'curves'.. same error.

I think I've run into that before. KSP is not very fault tolerant sometimes.

Are you using Unity 4.2.2? You'll need that version or earlier to animate the emissives this way. Later versions will let you edit it, but it won't work.

You have the animation lower in the tree, I'd go ahead and build it at the top GameObject. For the windows material, I'd leave the emissive color at black, and animate the colors only, not the opacity. When I use Animation, I also get a tree for everything in the gameobjects in that Animation window. So I always work my way down to the materials and edit the curves there. Screenies for my new pod:

KSP%202015-06-26%2010-00-00-01.jpg

KSP%202015-06-26%2010-00-00-02-0.jpg

Link to comment
Share on other sites

That's the problem then. I'm using Unity 5.1.0f3. Didn't dawn on me till you mentioned that. It also explains why all of the old screenshots and tuts look nothing like what I'm seeing. With Unity 5, you don't get the entire tree, you have to add the things you want animated individually. Is there going to be a new way of doing this in Unity 5?

-Edit- Ok, I got it working but boy, what a mess.

I found this post which sorta explained how to fix it.

1. I first had to go into Unity and Edit/Project Settings/Editor and change Asset Serialization to Force Text.

2. Save the scene

3. Open the .anim file in notepad and

a. Change every occurrence of classID: 23 to classID: 21

b. Change every occurrence of attribute: material._EmissiveColor to attribute: _EmissiveColor.

4. Go back into Unity and write the mbm.

For a small animation, I only had about 6 changes to make.

Some other quick notes on how I did this, whether it matters or not.

I opened the animation window, selected add property then drilled down to my main mesh and selected material.emissive.color. This also added a Color.a to the animation's list of attributes to change. I assumed that was the alpha so I deleted it. I was left with just the Color.r, .g and .b. I'm not sure if this is how previous versions of Unity worked but it was pretty easy to set the curves. I set the animation key frame to 0, opened the shader for my mesh and changed the EmissiveColor to black. I then moved the animation timeline to the 1.0 second mark, added a keyframe and changed the EmissiveColor to white. I then, as Necro suggested, added the animation component to the top level of the tree and drug the new animation file to it's 'Animation' edit box.

Thank you immensely Necro for taking the time to help me with this. You put me onto the right track for getting this fixed and hopefully, this solution will help others till KSP switches to Unity 5. I would have hated to have reverted to Unity 4.2.2, made all my animations and then had to go back to Unity 5.1 and redo all of them once Squad makes the change. At least this way, when KSP goes to Unity 5, all I hope I have to do is to save the scene again which hopefully replaces the .anim file and export (I got it working so I'm not about to overwrite the anim till I have to :D).

-edit- Ok, I got brave and saved the scene again after changing the curves. It did NOT overwrite the changes to the .anim file but it did change the curve values. I guess this means when KSP switches to Unity 5, I'll have to edit the .anim files again.

windows2.jpg

windows3.jpg

Edited by Fengist
Link to comment
Share on other sites

Glad to help! Awesome that it's working now. Yeah, I have no idea what's going to change with Unity 5, and whether we'll have to recompile our MUs or whatever. The part that I'm particularly terrified about is the wheel-collider stuff that's changing, since it'll probably break everyone's landing legs and landing gear.

Link to comment
Share on other sites

Glad to help! Awesome that it's working now. Yeah, I have no idea what's going to change with Unity 5, and whether we'll have to recompile our MUs or whatever. The part that I'm particularly terrified about is the wheel-collider stuff that's changing, since it'll probably break everyone's landing legs and landing gear.

HAH! Boats don't have either. I shall dodge the bullet. :) Thanks again.

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