I’m Making A Teleporter Function For My 2D Game. I’m not going off any tutorial, just winging it off my current experience and knowledge of coding. Everything was going well, but I encountered An Error When Teleporting Between Transform Positions. After Teleporting, My Player GameObject would be moved over by a fraction, and clip through the wall.
Immediately, The First Thing I thought of to fix it was to freeze the rigidbody constraints through An Interactions Script And Use A Time Delay To Stop The Player From Clipping Through The Wall. Although, I got this error which is preventing me from moving onto the next feature.
“error CS0266: Cannot implicitly convert type ‘UnityEngine.RigidbodyConstraints’ to ‘UnityEngine.RigidbodyConstraints2D’. An explicit conversion exists (are you missing a cast?)”
Here Is My Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DirectInteraction : MonoBehaviour
{
[Header(“Variables”)]
[SerializeField]
public float TeleportWaitTime;
Rigidbody2D playerrig;
void Start()
{
playerrig = GetComponent();
}
IEnumerator OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag(“Teleporter”))
{
playerrig.constraints = RigidbodyConstraints.FreezePositionX;
yield return new WaitForSeconds(TeleportWaitTime);
playerrig.constraints = RigidbodyConstraints.None;
playerrig.constraints = RigidbodyConstraints.FreezeRotationZ;
}
}
}
Anyone Know A Solution? This Has Been Really Bugging Me. Any Help Would Be Appreciated