Um, I suppose I don’t know vector3 very well, but I was working with a portal script i found on the internet and tried to change it to do what I want, which is change my position and rotation to the portal’s “spawn” gameobject which is used through public string to be the teleportTo var. The code that I had found on the internet worked for re-positioning, but didn’t include the rotation part, and if the portals are placed a certain way, the player flies threw them continuously until the player’s momentum has stopped. My change to the code does work, instantiating/deleting a string-ed player, which seems rather inefficient, it lags insanely, and does not let my grab/drop script work, since the player becomes a clone. I’d rather use a transform function, which simply moves & rotates the player. I attempted to a few different ways to get the transform to work, but none ever worked correctly. This code is the imitation of the function in which I want.
var teleportTo : Transform;
var player : GameObject;
function OnTriggerEnter (col : Collider)
{
if(col.gameObject == player)
{
Instantiate(player, teleportTo.position, teleportTo.rotation);
Destroy (player);
}
}
The error I got was
“The object of type ‘CapsuleCollider’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.”
which I understand why that is happening, just thought i’d note it.
What I was wondering was if there was a way which I have not learned (I have checked out the tutorials, some things I just need a better understanding of, as the tutorials understandably dont show every way to use the bit of code) to make the player onEnter of the portal’s trigger to go to teleportTo’s position and rotation. I would also rather the player lose all momentum than reflect it, it will not be used like valve’s portals. Thanks in advance, and I know, I need to study up on coding more, I’m just busy all the time, so I’d rather have the answer and description of why it works better than try to decipher other’s codes which don’t apply to my issue directly, and are difficult to apply to my issue.