Forum rules - please read before posting.

Tiny problem with "keep out of player's way" NPC setting

edited September 2022 in Technical Q&A

I generally have the "keep out of player's way" setting off, but I have created an action to turn it on or off depending on the context. One of times I use it is when an NPC enters the room to speak to the player. I teleport the invisible NPC to the door marker, then fade him in. That's when I momentarily turn the setting on so that, if the player happens to be standing right by the door, the NPC won't be too close while speaking to her.

I've found this works very well, EXCEPT when the player is standing exactly at the same coordinates as the door marker. Then the NPC won't move out of the way at all. I've tested whether this was really the issue by moving the player's x coordinate by 0.01, and sure enough, then the NPC moves out of her way.

TL;DR: it seems that the NPC only keeps out of the player's way if they are very close - but not exactly at the same place - as the player. Could we have this changed so the same coordinates will also trigger the behaviour?

Comments

  • I'll attempt a recreation, but the calculation involves only a straight distance check.

    What is your "Minimum distance to keep" value set to, and how does this compare with the size of your characters?

  • It's set to 4, and the characters aren't big. I made a video illustrating the issue, and I can upload it if you still need it, but I found the problematic code in NPC.cs. It involves lines like this:

    TryNavPoint (Transform.position - KickStarter.player.Transform.position);
    

    Because then under protected Vector3[] TryNavPoint (Vector3 _direction), you find:

    float currentDistance = _direction.magnitude;
    Vector3 _targetPosition = Transform.position + _direction.normalized * (minPlayerDistance - currentDistance) * 1.2f;
    

    In short, to find the target position, you're adding a number to the transform position, but the problem is that you're multiplying that number by _direction.normalized (which in this case is 0), so you aren't adding anything.

  • Yes, indeed. A correction will be issued, thanks for the bug report.

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.