Forum rules - please read before posting.

NPC hotspots are not working as intended when teleporting it.

Hi,
thanks for listening to my question first.

I have a problem with NPC hotspots, when I move or I scale NPC using Sorting Maps or Object Teleport ActionScript, the collider seems not to "follow" the parent object and stays "fixed" to the initial NPC position. Something may be missing or not correctly configured. But I can not figure out what it is happening. The hotspot is not actually working.
I tried to enable/disable Remembering scripts, renaming prefabs, changing Collider component, nothing seems to work.
I don't know what I'am missing .

See this for a demo.

Comments

  • You are adding 3D physics components - they will not be recognised by a 2D game.

    Use a Box Collider 2D or a Polygon Collider 2D component instead of a Box Collider.

    Try it with a Box Collider 2D, pause the game, and check where it's position is. Compare the NPC sprite child's Inspector (which has this component) before and after you run the game - it should remain the same, especially the collider's size and centre.

    If it's still on the left edge of the screen, how are you moving the NPC? Let's see the Action exactly.

  • edited January 2021

    Thanks for the Box Collider, I tried to apply your fixes but the problem still persists.
    When I start the game, the transform of the child object change just a little bit.. it changes from (0,0,0) to (0,0,0.03333334). The collider size and offset are the same.
    I move NPCs using an asset action list called "NPCIn" taking 5 parameter.

    0: The NPC scene GameObject
    1: A 2DMarker where I want to be moved.
    2: The Hotspot (I used to pass the child object)
    3: HasMarker, true if I want to teleport the marker
    4: HasHotspot, true if I want to enable the hotspot

    The action list asset is something like this.

    https://ibb.co/8mMpjBZ

  • In this second scenario, I don't move the NPC's using that asset action list but script instead.

    private void Walk(AC.Char character, float x, float y)
    {
        Vector3 point = new Vector3(x, y, 0);
        character.MoveToPoint(point,false,true);
    }
    
  • Thanks for the Box Collider, I tried to apply your fixes but the problem still persists.

    The Box Collider did at least appear to move with the NPC, unlike the Polygon Collider 2D. What specifically happens if you add the Box Collider 2D?

    Your NPCs should not have a Remember Transform component attached - the Remember NPC component will record their position in save-game files.

    When I start the game, the transform of the child object change just a little bit.. it changes from (0,0,0) to (0,0,0.03333334)

    That's likely caused by the Follow Sorting Map, which will slightly adjust the sprite child's Z position if two characters are in the same region, to ensure they're rendered in the correct order.

    Since that only affects local position, though, that shouldn't be causing an issue. What is the effect of temporarily removing the NPC's Follow Sorting Map component? Does the collider then move as the NPC is teleported?

    You don't strictly need to keep your collider + Hotspot components on the sprite child - you can move them to the NPC's root object. Just be sure to also uncheck Turn root object in 3D? in the NPC Inspector, so that they don't change their rotation.

  • Thanks for your fast responses, I added the Box Collider 2D to the NPCs of the first scenario but even with 2D Box Colliders the problem still persist.

    I removed the remember transform components from NPC prefabs, thanks for your advice.

    Disabling temporarily the NPC's Follow Sorting Map doesn't affect the NPC collider position. But your hint suggested me to check other toggles...

    I've noticed that enabling/disabling "isTrigger" toggle while running the game, the collider update its center position!

    Here a video showing this strange behaviour while the NPC is moving... Don't know if can be usefull to understand what is happening here..

  • Very odd. I can't recreate such behaviour, myself, though.

    Try temporarily removing all non-essential components, both from the child and the parent - including the Animator and any other Remember component you may have.

    If still no luck, you're welcome to PM me a minimal package with an NPC prefab, Managers, and a scene to demonstrate the issue - and I'll take a look. At this stage, though, it is looking more like an issue with Unity.

  • This might be related to what I was struggling with here:
    https://www.adventurecreator.org/forum/discussion/10981/npc-hotspot-placement#latest

    If you add a new game object as a child of your NPC SpriteChild, and move both the Hotspot and BoxCollider component there - does that fix it for you?

  • Hi @ChrisIceBox , I tried to..

    • disable components on NPCs but nothing seems to change;
    • update unity to the latest LTS version, now is 2019.4.18f1 (I was working with a minor LTS) but the problem still persist;
    • remove all unnecessary unity folder and rebuilt the entire project with no change;

    I'm going to write to you a PM.

  • Hi,
    after creating the package, I wanted to verify that it was made correctly, so I started a new project, reinstalled AC, imported the package and.. the problem was fixed!
    So I made these steps for my entire project (this time exporting all assets as package) and the problem seems to be corrected.

    I tried to figure out what changed from the new "fresh project" and my old one, but the only differences I found were under the "Package" folder (It seems that some of *2D folder were missing in the old project).
    I don't know what happened but in my opinion this problem was introduced by several unity/AC version upgrade.

    I did not tried your work around @kloot because of that. Sorry.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.