Login / Registrieren
DE EN FR ES IT CZ
Zurück Nach oben

Questions to: Talking with NPC characters

  • #1, by Lebostein 11 years ago Zitieren
    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.
  • #2, by afrlme 11 years ago Zitieren
    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?


  • #3, by Lebostein 11 years ago Zitieren
    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"?
  • #4, by afrlme 11 years ago Zitieren
    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?
  • #5, by Lebostein 11 years ago Zitieren
    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...
  • #6, by afrlme 11 years ago Zitieren
    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
    
  • #7, by Lebostein 11 years ago Zitieren
    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
  • #8, by sebastian 11 years ago Zitieren
    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...
  • #9, by Lebostein 11 years ago Zitieren
    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?
  • #10, by afrlme 11 years ago Zitieren
    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")
    
  • #11, by Lebostein 11 years ago Zitieren
    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