Jump to content

What does it take to teleport?


Recommended Posts

I was trying to teleport ships a while ago for my wormholes plugin. I came up with a crude way of doing it that you can read through in that plugin\'s source. Ultimately I was setting vessel.transform.position to the desired world position vector, but I believe I found that if you did this to a ship that was loaded and running physics, only the command pod would teleport, and as a result the ship would be decapitated. But I found that if you set vessel.transform.position for an unloaded, on-rails vessel, the whole ship would teleport. So I devised a hacky solution where I had the teleport code change the active vessel to a distant vessel, causing the original vessel to go on rails, then code running on the distant vessel would teleport the original vessel, then switch back to the original vessel. It took some care not to crash the game doing this, and it wasn\'t particularly smooth or reliable, which is part of the reason I haven\'t worked on that plugin in a while.

But likely my failure to find a good way of doing this is due to my complete ignorance of how Unity works.

Link to comment
Share on other sites

Bingo!

The_Duck, thanks for the insight. I think with that I\'ve figured out an important step towards destruction-free teleportation.

1) The ship can\'t be resting on the pad. First you have to (one way or another) get it to not be contacting the ground

2) call something like the following code:

vessel.GoOnRails();

vessel.transform.position = new Vector3(0, 0, -100000);

vessel.GoOffRails();

Bam! Your vessel now up 100,000m. No switching of perspectives or other shenanigans.

Link to comment
Share on other sites

I actually can\'t access your source for that file (winrar says there\'s an unexpected end of file) - how did you normalize the relative velocities of the objects?

That is, when you moved the vessel to another area, how did you also get it to enter the same orbit?

Link to comment
Share on other sites

Ah, yeah, all forum attachments got messed up in the recent server moves, I think. I\'ve edited mediafire links into that post.

Adjusting vessel velocities is easy: use vessel.SetWorldVelocity(Vector3d) to or vessel.ChangeWorldVelocity(Vector3d). If you want to zero out the velocity relative to some other vessel, you can get that vessel\'s velocity using vessel.orbit.GetVel().

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