Forum rules - please read before posting.

Making the player walk up to an NPC

edited December 2017 in Technical Q&A
Hi,
I am struggling to accomplish the following and I hope that someone here can help;

A. The player clicks on an NPC that is walking about the scene on a looping path.
B. The NPC stops moving along the path and faces the player.
C. The player than walks up to the NPC and stops an arm length away to start a dialogue.

My flawed workflow for this is;
A. After clicking the NPCs hotspot, kill the NPCs AI actionlist and stop it from moving.
    Face the player.
B. Then I record the NPCs position as a local V3 variable and instantiate a marker (prefab) at that location.
C. The player then "Moves to point" to that marker.

The problem is that the marker isn't created exactly at the NPCs position for one (???), and even if it was, it would still have to have an offset (in the NPCs facing direction) to where the player stops short of the NPC and doesn't run into him.

I've played around with creating the marker at NPCs position and then parenting it to the NPC. The NPC would then rotate to face the player and rotate the marker along with it.
But that didn't work, because it seems that changing a markers position at runtime is being ignored and the player just moves past the markers position.
And there is also this odd rotating around of the NPC.

Does anyone have an idea on how to accomplish this seemingly basic player / NPC interaction?

Thanks!
Kay


image

Comments

  • You're recording the NPC's local position, as opposed to global - try switching so that you're using world-space co-ordinates.

    You can also keep the Marker_NPC in the scene hidden away and simply move it, as opposed to spawning one each time.  That will prevent errors with e.g. repeated clicks causing multiple markers spawning and it getting confused about which one to refer to.

    The exact position of the marker would likely need some simple custom scripting - I'd say it would be easier to have a custom Action that correctly places the Marker without need for a Local Vector3 Variable, as you could then incorporate a dynamic offset that places the marker in between the player and the NPC for something more natural.

    However, you might instead be able to make use of the Hotspot's "Player Action" field in the Interaction panel.  When set to "Walk To", you can set a proximity value - allowing you to have the player get close to the Hotspot without being exact, which is helpful when the exact location to move to is unknown.

    You could then have a separate ActionList that simply kills the AI loop / stops the NPC from moving while the player is walking towards her.  That could be down with the OnHotspotInteract custom event, e.g.:

    http://pasteall.org/725993/csharp
  • edited December 2017
    Thanks for your reply Chris!

    I will give that a shot and see if I can get it to work.
    I guess a little scripting is inevitable, but that's no big deal.

  • edited December 2017
    I figured it out. Without touching MonoDevelop.. ;)

    Instead of instantiating a marker, I am now moving a marker around.
    Added a dummy cube that gets moved to the NPCs position and gets offset in the NPCs Z axis.
    Then the cube is parented to the NPC and the NPC rotates to face the player.
    Rotating the cube along with it.

    This places the cube in front of the NPC with the offset, facing the player.
    The dynamic marker then is moved to the cubes location and the player will walk up the the NPC.

    That easy.

    image
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.