How are your spawn points looking?

Any places you’ve got stuck so far?

in here, we noticed an issue, with moving the character, its true disabling the NavMeshAgent is okay, and can work, but i would find it, rather confusing, so another solution i’d like to suggest would be

player.GetComponent<NavMeshAgent>().Warp(portalPosition);

the NavmeshAgent itself has a Warp function, it basically teleports the character to the destination position on the NavMesh, i find that a more direct solution rather than the disabling, which can be confusing.

4 Likes

Noice! I didn’t even know that existed. Great find.

So should I have my code like this after I implement the save stuff…

private void updatePlayer(Portal otherPortal) {
            GameObject player = GameObject.FindWithTag("Player");
            player.GetComponent<NavMeshAgent>().enabled = false;
            player.GetComponent<NavMeshAgent>().Warp(otherPortal.spawnPoint.position);
            player.transform.rotation = otherPortal.spawnPoint.rotation;
            player.GetComponent<NavMeshAgent>().enabled = true;
            // Course code before adjustment by Sam
            //player.transform.position = otherPortal.spawnPoint.position;
            //player.transform.rotation = otherPortal.spawnPoint.rotation;
        }

or like this?

private void updatePlayer(Portal otherPortal) {
            GameObject player = GameObject.FindWithTag("Player");
            player.GetComponent<NavMeshAgent>().Warp(otherPortal.spawnPoint.position);
            player.transform.rotation = otherPortal.spawnPoint.rotation;
            
            // Course code before adjustment by Sam
            //player.transform.position = otherPortal.spawnPoint.position;
            //player.transform.rotation = otherPortal.spawnPoint.rotation;
        }

I ask because I didn’t see any difference either way. I just know that the portals worked fine before I added the save stuff, now they are broken again. they will not load the next scene.

Either should achieve the same thing.

GameObject player = GameObject.FindWithTag(“Player”);

        player.GetComponent<NavMeshAgent>().Warp(otherPortal.spawnPoint.position);

        player.transform.rotation = otherPortal.spawnPoint.rotation;
1 Like

this is not working correctly. the problem is when i start playbutton and go through portals always stuck around 0.2/0.4 sceconds at spawnPoint and directly spwans to playerold position.

please give me some instructions.using System;
using System.Collections;

using UnityEngine;

using UnityEngine.SceneManagement;

using UnityEngine.AI;

namespace RPG.SceneManagement

{

Copy to clipboard
public class Portal : MonoBehaviour

{

enum  DestinationIdentifier

{

    A, B, C, D, E

}

[SerializeField] int sceneTOLoad = -1;

[SerializeField] Transform spawnPoint;

[SerializeField] DestinationIdentifier destination;

private void OnTriggerEnter(Collider other)

{

    if( other.tag == "Player")

    {

        StartCoroutine(Transition());

    }

}

private IEnumerator Transition()

{

    if(sceneTOLoad < 0)

    {

        Debug.Log("Scene to load not set");

        yield break;

    }

    DontDestroyOnLoad(gameObject);

    yield return SceneManager.LoadSceneAsync(sceneTOLoad);

    

    Portal otherPortal = GetOtherPortal();

    UpdatePlayer(otherPortal);

    Destroy(gameObject);

}

 private void UpdatePlayer(Portal otherPortal)

{

    GameObject player = GameObject.FindWithTag("Player");

    player.GetComponent<NavMeshAgent>().Warp(otherPortal.spawnPoint.position);

    player.transform.rotation = otherPortal.spawnPoint.rotation;

}

private Portal GetOtherPortal()

{

    foreach (Portal portal in FindObjectsOfType<Portal>())

    {

        if(portal == this) continue;

        if(portal.destination != destination) continue;

        return  portal;

    } 

    return null;

}

}
}
sir this is my code from lecture #73 i watched video many times and try to settle things but cant find any solution my problem is whenever i enter in the portal player quickly spawn to its old position and never spawns to portalspawn position please help me and give some helpful instructions.

Are there any error messages showing in the console when you do this?

I have the same problem. I did everything exactly step by step as you did in the lecture. But when player hit the portal, he spawns at spawnpoint as i expected, but then after a 0.5 seconds he respawns at his origin location in the scene.

Once again, does the Console yield any error messages?

Thank you, it fixed my problem that my player is not spawning on the spawnPosition when changing to sanbox2 scene.

1 Like

Privacy & Terms