Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Cannot move objects between 2 different terrain objects in the same Scene

Discussion in 'Editor & General Support' started by Gronendael, Dec 6, 2020.

  1. Gronendael

    Gronendael

    Joined:
    Nov 10, 2014
    Posts:
    2
    Working on an RTS where my workers must gather resources and return them to their "home base", a Fort.

    The Fort is a totally separate area/view than the world. For example, a worker gathers berries in the world, then moves back to the Fort object. In the outside world view, the Fort appears small, just a cube object at the moment. When the worker collides with the Fort cube object, he should be taken to the Fort area/view that has buildings, a market, etc.

    So simultaneously, there are workers inside the Fort view and outside in the world view.

    The player should be able to switch back and forth between the outside world view and the Fort view quickly.

    The outside world terrain object starts at (0,0,0) and Fort terrain object starts at (0,0,35), so I'm working with small areas just prototyping. There is a small gap between them.

    Currently I am simply trying to "teleport" the worker object from the cube Fort in the world view to a specific position in the Fort view...
    Code (CSharp):
    1. transform.position = new Vector3(-15, 0, 50);
    But when I do this, the worker is blocked by the boundary of the world view and stays on the world terrain object. I cannot move him over to the Fort terrain object. Not sure if this is NavMesh related or what. I have the NavMesh baked for both areas and if I just drop a worker in the Fort, he wanders fine.

    - Should the outside world view and the Fort view be 2 separate areas within 1 scene? Maybe this is not how I should be setting this up.

    - How else should I have 2 simultaneous areas like this? 2 separate scenes that run at the same time? Is there another way?

    Hope I explained this well. Thanks for any thoughts!
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    I don't have a lot of experience with NavMesh but it sounds like it could be related. I've had similar issues with CharacterController though and used a workaround like this:
    Code (CSharp):
    1. public void TeleportTo(Vector3 position) {
    2.   myCharacterController.enabled = false;
    3.   transform.position = position;
    4.   myCharacterController.enabled = true;
    5. }
    Maybe something similar would work with NavMeshAgent?

    Alternatively, try the Warp method on NavMeshAgent?
    https://docs.unity3d.com/ScriptReference/AI.NavMeshAgent.Warp.html
     
    Gronendael likes this.
  3. Gronendael

    Gronendael

    Joined:
    Nov 10, 2014
    Posts:
    2
    Yes! Warp worked like a charm. Thank you so much.
    Code (CSharp):
    1. var nm = GetComponent<NavMeshAgent>().Warp(entryPoint.Value);