Questions to: Talking with NPC characters

  • #1, by LebosteinSunday, 12. July 2015, 18:48 5 years ago
    1. If I click on an NPC (with no fixed position) the player character walks to the NPC. How I can set at which position the player character should stop (relative to the NPC)? What is the implemented rule? It seems the player character stops with a specific distance to the NPC.

    2. How I can align an NPC character face to face to the player character? If I click on an NPC to interact with it, the player character walks the shortest path to the NPC. Sometimes the player character stops behind the NPC. Now I have to align the NPCs face to the player character.

    Key Killer

    598 Posts


  • #2, by afrlmeSunday, 12. July 2015, 20:54 5 years ago
    I believe you could specify the interaction position via lua script. It even says it's scriptable according the data structure which means that it will retain the new position in the save game data. If you plan on moving the NPC around the scene, or multiple scenes, then I would recommend updating the position by executing some if queries on mouse over. If the NPC is walking around then it would be a better idea to have it update the position via a loop. Or have the NPC stop as soon as you left click on it, then set the position based on the characters position plus / minus an offset.

    Example #1
    Characters["Tom"].ActionDestPosition = {x = 100, y = 500} -- specific coordinates
    1
    2

    Example #2
    local char = Characters["Tom"] -- store char in variable
    local pos = char.Position -- store char position in variable
    char.ActionDestPosition = { x = pos.x, y = (pos.y + 50)} -- update destination position
    1
    2
    3
    4


    I wrote some functions a few months or so back which you can use to align characters to objects or other characters. However they currently align based on the animation center which is usually set to the feet - which I guess is pretty much the same method used in the auto-align on immediate execution option?


    Imperator

    6812 Posts

  • #3, by LebosteinMonday, 13. July 2015, 12:09 5 years ago
    For the face to face communication I use this:
    if game.CurrentObject:getId().tableId == eCharacters then
    local exchar = game.CurrentObject -- character I talk with
    local mychar = game.CurrentCharacter -- my character
    if mychar.Position.x < exchar.Position.x then mychar.Direction = 0; exchar.Direction = 180 end
    if mychar.Position.x > exchar.Position.x then mychar.Direction = 180; exchar.Direction = 0 end
    end
    1
    2
    3
    4
    5
    6
    7

    I call this script as the first action part in any "talk with" actions. But sometimes the code don't work. I have no idea why this code only work in 50 % of the cases... could it be that the "current object" is very short-lived? How I get an access to the "saved object"?

    Key Killer

    598 Posts

  • #4, by afrlmeMonday, 13. July 2015, 14:16 5 years ago
    CurrentObject is the object currently underneath the cursor. You need to on mouse over set the current object as the saved object, which you could do with action parts or Lua script.

    So you are using scene objects for close-up talk scenes?

    Imperator

    6812 Posts

  • #5, by LebosteinMonday, 13. July 2015, 15:00 5 years ago
    No. I talk only with real characters. If I replace "CurrentObject" with "SavedObject" in the script above then nothing happens. It seems the "SavedObject" is empty...

    Key Killer

    598 Posts

  • #6, by afrlmeMonday, 13. July 2015, 15:55 5 years ago
    If it's a character then why not align to the character? You have to manually save an object to the system to add it to the saved object table, hence: on mouse over > save object. This will set the saved object to whatever was under the cursor at the time you triggered the save object action. Of course you could do this with Lua too.
    game.SavedObject = game.CurrentObject
    1
    2

    Imperator

    6812 Posts

  • #7, by LebosteinMonday, 13. July 2015, 16:19 5 years ago
    OK, now I have it. I use two scripts. Script 1 is called from the interface button (left click) and Script 2 is called as the first action part inside every "talk to" action.

    Script 1:
    last_saved_object = game.SavedObject
    1
    2

    Script 2:
    if last_saved_object:getId().tableId ~= eCharacters then return end
    local exchar = last_saved_object
    local mychar = game.CurrentCharacter
    if mychar.Position.x < exchar.Position.x then mychar.Direction = 0; exchar.Direction = 180 end
    if mychar.Position.x > exchar.Position.x then mychar.Direction = 180; exchar.Direction = 0 end
    1
    2
    3
    4
    5
    6

    Now the two talking characters turn to each other before they talk wink

    Key Killer

    598 Posts

  • #8, by sebastianMonday, 13. July 2015, 16:29 5 years ago
    why isnt that the default acting anyway?
    When talking to a char the current char should go to a specific or relative coordinate and then further actions should follow when the exact destination is reached...

    Thread Captain

    2336 Posts

  • #9, by LebosteinMonday, 13. July 2015, 16:42 5 years ago
    But an open question remains: How Visionaire calculate the walk-to-point if I click on an NPC and how I can modify these default setting? It seems the player character stops, if he reach an specific radius around the NPC. But what size is this radius?

    Key Killer

    598 Posts

  • #10, by afrlmeMonday, 13. July 2015, 16:44 5 years ago
    What is the query line for in the main block?
    if last_saved_object:getId().tableId ~= eCharacters then return end
    1
    2


    return what?

    local char

    function alignChar(npc)
    npc = Characters[npc]; char = game.CurrentCharacter
    if char.Position.x <= npc.Position.x then
    char.Direction = 0; npc.Direction = 180
    else
    char.Direction = 180; npc.Direction = 0
    end
    end
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    usage...
    alignChar("Tom")
    1
    2

    Imperator

    6812 Posts

  • #11, by LebosteinMonday, 13. July 2015, 16:46 5 years ago
    My scripts (as execution scripts) works automatically with the talking characters. There is no need to define a specific name and it is possible to use my script inside other action parts. wink

    Key Killer

    598 Posts

Write post