Teleport a rigidbody

Hi,

i want to releport my rigidbody. I will add a Force and if the rigidbody touches the trigger i will move the rigidbody to another position and the force should continue. The problem is the rigidbody is going crazy after moving. This is what im doing:

function OnTriggerEnter(other : Collider) {
//this is my rigidbody gameobject
other.gameObject.transform.position = exit.transform.position;
}

Looks fine to me. Maybe something else is causing the issue.

you can sleep it, then move the rigidbody (through rigidbody.position, not transform position) and wake it again. that should work I think.

i tried it but the behaviour of the rigidbody is not always the same. Sometimes it will drop down like a stone and sometimes it will be faster as before

Have you tried something like this:

  1. store rigidbody.velocity
  2. store rigidbody.angularvelocity
  3. sleep rigidbody
  4. deactivate gameObject
  5. move gameObject
  6. activate gameObject
  7. forcibly reset rigidbody.velocity/angularvelocity
  8. wake rigidbody

Maybe swapping 7/8 if the first attempt doesn’t work? You prooobably don’t need to deactivate the gameObject, but you said simply sleeping/waking the rigidbody wasn’t working - so it’s worth a shot.

the way to move it would be:

  1. record the velocity. (rigidbody.velocity)
  2. set the rigidbody to kinematic (isKinematic = true)
  3. move the transform to the new location
  4. set isKinematic = false
  5. recompute the new velocity direction (that is based on the in and out portals orientations and the initial rigidbody velocity)
  6. set rigidbody.velocity = to the transformed initial rigid body velocity.

EDIT: I just saw that Kyle posted 3 min. before me.
I did not post to correct his approach. In fact his approach seems good to me. If the portals are oriented in the same way, you don’t have to worry about transforming the velocity vector.

No offense taken :smile:
I don’t work with rigidibodies for the most part; was just a stab-in-the-dark attempt on my part. Didn’t even think to take the orientations of the portals into consideration :slight_smile:

Whatever gets the OP up and running is, as they say, for the win.

@ivkoni @KyleStaves i tried your approaches but the problem is the same. The behavior is not always the same. Sometime the rigidbody goes crazy. Sometimes it drop downs… :frowning:

1 Like

I’d check to make sure you don’t have anything solid in the destination area that the object could intersect with. If you do, it’ll cause the crazy physics you’re experiencing.

1 Like

It’s absurd that Unity makes these things so difficult.

You can set the Rigidbody.position to make it instantly move to that position.

TBH what is absurd is necro-posting to a 12 year old thread to complain about such a simple thing.

Please don’t do this, there’s got to be a much more productive use of your time here. :slight_smile:

4 Likes

To be fair what you’re saying is patently false and does not work, even now as I come across this thread another 2 years later.

I have built a “shifting world” system (to keep the character near the origin in big worlds) 3 different times over the course of 6+ years working in Unity. Each time has been a pain in the ass. Each time a subtly different solution is needed (as the versions of Unity seem to break my previous solutions over time).

Just wait until you need to shift a full character rig with ragdoll rigidbodies and joints. That is my current predicament and none of the solutions on this thread seem to work reliably. It’s ridiculous…

2 Likes

If you try to just simply set new Rigidbody.position and it goes crazy, remember to set interpolation to none before the teleportation and reset it back afterwards. Was my case of all issues.