Questions to: Talking with NPC characters

  • #1, by LebosteinSunday, 12. July 2015, 18:48 9 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

    621 Posts


  • #2, by afrlmeSunday, 12. July 2015, 20:54 9 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
    

    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
    


    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

    7278 Posts

  • #3, by LebosteinMonday, 13. July 2015, 12:09 9 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
    

    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

    621 Posts

  • #4, by afrlmeMonday, 13. July 2015, 14:16 9 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

    7278 Posts

  • #5, by LebosteinMonday, 13. July 2015, 15:00 9 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

    621 Posts

  • #6, by afrlmeMonday, 13. July 2015, 15:55 9 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
    

    Imperator

    7278 Posts

  • #7, by LebosteinMonday, 13. July 2015, 16:19 9 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
    

    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
    

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

    Key Killer

    621 Posts

  • #8, by sebastianMonday, 13. July 2015, 16:29 9 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

    2346 Posts

  • #9, by LebosteinMonday, 13. July 2015, 16:42 9 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

    621 Posts

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


    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
    

    usage...
    alignChar("Tom")
    

    Imperator

    7278 Posts

  • #11, by LebosteinMonday, 13. July 2015, 16:46 9 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

    621 Posts