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;
}
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
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.
set the rigidbody to kinematic (isKinematic = true)
move the transform to the new location
set isKinematic = false
recompute the new velocity direction (that is based on the in and out portals orientations and the initial rigidbody velocity)
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
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
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…
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.
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…
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.