Question by
TheOneMiner · Oct 30, 2021 at 12:12 PM ·
navmeshagentnavigation
How to change players position through baked GameObjects?
I have this game of a school I'm working on and as the school is quite simple, I decided to make the model in Unity. I try to make doors that teleport the player through the wall inside the school. My player works with navmeshagent and as I have baked the walls and ground and all, when I try to tp the player it doesn't go in the school. It just can't get inside and leaves the player facing the wall.
Here's my door script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Door : MonoBehaviour
{
public Transform other;
float minDist = 5;
public Transform teleport;
void Update()
{
if (other)
{
float dist = Vector3.Distance(other.position, transform.position);
if (Input.GetKeyDown(KeyCode.E))
if (dist < minDist)
{
print("Teleported");
Teleport();
}
}
}
void Teleport()
{
other.transform.position = teleport.transform.position;
}
}
Comment
Your answer