Jump to content

Position one craft relative to another


Recommended Posts

I've seen this question asked in a few other contexts, but either they weren't ever answered, or the answers weren't helpful in my case. Regardless, here's hoping someone knows the answer, here!

I'm trying my hand at modding, and I figured I'd pick something simple and science-fiction-ish -- a teleportation mod! OP, sure, but it's mostly just for learning the ropes anyway.

The idea is this. You send up a ship with this part on it. You dock it to another ship with the same kind of part, and then "entangle" the two. (You know, like quantum entangling...? Yeah.) Then you fly one of the two ships to some other (presumably distant) location and forget about it.

The good part: you fly another ship to the nearest of the two nodes and dock. Then you say "teleport", and voila! The ship magically appears in the vicinity of the corresponding entangled part.

I've got it mostly working... You dock two nodes, entangle them, etc. Even the teleport works---you can send a ship to within 30 m of the twinned vessel.

THE PROBLEM: I want the ship to appear "in front" of the target node, aligned with it (but not necessarily docked with it). However, everything I've tried keeps putting the vessel off in some other direction. The magic occurs on lines 49-68 of the following file: https://gist.github.com/jamis/35a48a80bce87f349ae6#file-moduleteleportationnode-cs-L49-L68 . The facing that gets computed on line 57 is local to the part (or something), but I can't seem to figure out how to convert it to worldspace.

Help? Thanks!

Link to comment
Share on other sites

disclaimer - I have no "real" clue what I'm talkin about..

It seems you try both in one step - facing and positioning..

Did you try to use "Rotation" for this instead of position?

I would suggest either of these ways..

- create a quaternion-rotation to make it in one step or

- first position your ship with one vector, than align it with the LookAt function..

I hope it helps - but usually I just keep trying until it works - and usually I am not really sure why it suddenly works..

my vector math knowledge is 2 decades old and was generally ignored for that long..

..hence the disclaimer..

Link to comment
Share on other sites

Thanks for the suggestion! I'll give that some more thought. I'd considered trying rotations but got stymied trying to figure out the order of operations, there. Time to do some more tinkering, I guess. :)

Link to comment
Share on other sites


Vessel leader_v = FlightGlobals.ActiveVessel;

// add here your positioning code without the "facing" vector
// Do stuff


// this will do the rotation
Vector3 LeaderHeading = (Vector3)leader_v.transform.forward;
Quaternion newRotation = new Quaternion();
newRotation.SetLookRotation(LeaderHeading, leader_v.transform.up);
thisVessel.SetRotation(newRotation);

hope that helps..

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