Jump to content

Use any part as a camera to view from?


Xavier513

Recommended Posts

I'm trying to create a mod to use any part in a vessel as a camera. With this mod, I can view from any part in a more realistic way, without any new camera parts.

For example, I can view from the bottom of engines, or view from pods in forward direction, or view from the top edge of fuel tanks(so I can see booster seperation).

But I'm not familiar with either manipulating cameras or Unity engine, so I'm not quite sure about how to achieve this.

My thoughts about this mod are:

1, Add a button in the right-click menu of each part.

2, If the button is clicked, the mod will create a new Camera object for this part.

3, Init the Camera object with the part's orientation(position + rotation), and some offsets.

4, Activate the new Camera, and view from it.

I have to figure out how to implement each step, but the first question is, am I right about those steps? If I'm wrong, what is the right way to do that?

Thanks!

Edited by Xavier513
Link to comment
Share on other sites

Start with taking a look at hullcamvds that'll give you an idea of what's required.  A camera is essentially a part module you have to slap on to existing parts at the very least, so patching all parts in ksp with a camera may have unintended consequences

Link to comment
Share on other sites

13 hours ago, Xt007 said:

Start with taking a look at hullcamvds that'll give you an idea of what's required.  A camera is essentially a part module you have to slap on to existing parts at the very least, so patching all parts in ksp with a camera may have unintended consequences

After some learning and testing, following codes can do the trick:

FlightCamera.fetch.SetFoV(50);
Camera.main.nearClipPlane = 0.1f;
FlightCamera.fetch.SetTarget(null);

GameObject parent = new GameObject("parent");
FlightCamera.fetch.transform.parent = parent.transform;

Part p = ... // any part in the vessel
parent.transform.position = p.transform.position + p.transform.rotation * new Vector3(offsetX, offsetY, offsetZ);
parent.transform.rotation = Quaternion.AngleAxis(offsetDegree, engine.transform.right) * Quaternion.LookRotation(-p.transform.up, -p.transform.forward); // this is the correct rotation for engine parts

It simply changes position and rotation of player's camera.

But the camera seems to rotate around an point at about 75 units far, still don't know how to change that point and make it closer:/

Edited by Xavier513
Link to comment
Share on other sites

6 hours ago, Xavier513 said:

But the camera seems to rotate around an point at about 75 units far, still don't know how to change that point and make it closer:/

I could be way off here, but you could try maing a model (a .mu), that only contains an empty transform, that could be added into any part .cfg as an additional model, and manipulted with some existing config modules and keys, or using some mods' modules & keys (such as B9 PartSwitch, mebbe vOv)... especially position and rotation

But then, you'ld still want some ind of plugin as a controller

Edited by Stone Blue
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...