Jump to content

Get direction of part?


Recommended Posts

I want to keep track of a hatch's rotation, so that I can spawn a part a few inches out from it. So that no matter how the part was rotated in VAB, and/or rotated while in flight, the new part always spawns in front of the hatch. I've tried about 100 different methods and all of them break down if the ship rotates.

Is there an easy way to achieve this?

Link to comment
Share on other sites

You can get a part's up vector in worldspace by calling part.transform.up. You can use this along with the part.transform.position to instantiate an object directly in front of your part at an arbitary distance. Also, if you need to keep track of rotation, you may want to copy part.transform.rotation an apply it to your new object as well. The Unity docs are particularly helpful for these kinds of operations, and it can help to familiarize yourself with the local/global coordinate systems and transforms.

I hope that helps!

Link to comment
Share on other sites

Keep i mind that parts in KSP have a silly interpretation of up and forwards relative to the normal way of doing things in Unity.

Up (y) in KSP is the rocket nose, and forward (z) is the heads up direction in a plane cockpit. Normally forward/z is the direction of travel in Unity, and therefore any examples using LookAt for instance will be confusing.

Also remember to use transform.localPosition and not the global transform.position in all cases where you move stuff inside a part (and localRotation of course)

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