- Home /
Teleportation problem!
I wrote a portal script but whenever i teleport my character it happens to teleport without an arm,how could i connect the body pieces so it teleports completely
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Teleporter : MonoBehaviour
{
public Teleporter Other;
private void OnTriggerStay(Collider other)
{
float zPos = transform.worldToLocalMatrix.MultiplyPoint3x4(other.transform.position).z;
if (zPos < 0) Teleport(other.transform);
}
private void Teleport(Transform obj)
{
//Position
Vector3 localPos = transform.worldToLocalMatrix.MultiplyPoint3x4(obj.position);
localPos = new Vector3(-localPos.x, localPos.y, -localPos.z);
obj.position = Other.transform.localToWorldMatrix.MultiplyPoint3x4(localPos);
//Rotation
Quaternion difference = Other.transform.rotation * Quaternion.Inverse(transform.rotation * Quaternion.Euler(0, 180, 0));
obj.rotation = difference * obj.rotation;
}
}
I mean honestly, just briefly looking at the script,...i thought Unity is game engine not a rocket propulsion science. Although.. Unless i am interpreting it badly, you could
public Transform TeleportEnd;
Void OnTriggerEnter(Collider other)
{
other.transform.position = TeleportEnd.position;
other.transform.rotation = TeleportEnd.rotation;
}
Answer by thomh_unity · Oct 31, 2019 at 10:18 AM
Hi Bogdan003,
If your character has multiple colliders then it's possible you're just moving the transform that the body collider is on.
If the collider is a child of your character's root object then you can use:
Transform parent = other.transform.parent;
Teleport(parent);
If the heirachy is more complex then you can get the root transform for the collider like this:
Transform root = other.transform.root;
Teleport(root);
I hope this helps!
Your answer
Follow this Question
Related Questions
Portal between scenes? 3 Answers
How to keep an Enemy from teleporting outside of a room. 1 Answer
Collision for Amount of Time 1 Answer
making a non walk through portal 2 Answers
teleportation 1 Answer