Set character to character

  • #1, by guusThursday, 17. July, 00:47 2 days ago
    Hi! I'm looking for an options to set a character to another character, does something like that exists?

    My dilemma is this: I'm making an adventure game (curse of monkey island-style), and there is a magic sword in the inventory at some point. However, when you talk to the sword in the inventory, it should show up on screen next to the main/current character, as an character this time, so the player can talk to it. This needs to be possible at every scene. 

    Right now when it's being talked to I'm 
    - hiding the sword character, 
    - have it set to a position on the screen and then 
    - chase the current character and then 
    - show the sword character , 

    but since all the way borders are very different on every scene it isn't possible on all the scenes, there is simply not a coordinate on screen where this trick works on every scene.

    Newbie

    9 Posts


  • #2, by philip-schoenmetzThursday, 17. July, 07:54 2 days ago
    Why not just make additional outfits with the MC and the sword. I haven't scripted anything yet, but maybe there is a get player position.

    Newbie

    6 Posts

  • #3, by esmeraldaThursday, 17. July, 12:06 Yesterday
    There are some custom action part plugins that might help.
    https://wiki.visionaire-tracker.net/wiki/Action_Part_Plugins

    None for setting the character, though - only sending and aligning.

    So I guess scripting would be better.
    Something along these lines:
    local dist -- variable for the distance to the main character
    function setChar()
    
      local charPos = game.CurrentCharacter.Position -- Position of the main character
    
    Characters["Sword"].Scene = game.CurrentCharacter.Scene  -- set the sword character on the same scene of the main character
    
      if charPos.x - 100 < 0 then  -- check if the position of the sword would be off the screen
    
        dist = 100
    
      else
    
        dist = - 100
    
      end
    
      Characters["Sword"].Position = {x= charPos.x + dist, y=charPos.y}  -- set the sword on the same position as the main character 100 px to the side
    
      Characters["Sword"].Active = true -- show character (only necessary if you hid the characer, else setting the character somewhere off screen would be enough to hide it)
    end
    
    
    
    -- call this function with an execute script action part and put the line:  setChar()   in it
    
    -- change the name of the character to yours and adjust the position to your liking


    And please feel free to drop by in the discord server of VS. 


    Key Killer

    541 Posts

  • #4, by guusThursday, 17. July, 15:30 Yesterday
    Wow, you're fantastic! That did work.

    Only problem I'm still running into is that if the sword is picked up at a spot where there is an object on the screen the sword isn't clickable anymore; the object takes precsidence. (See screenshot: the sword was put on the scene in front of the door and now the cursor only acklowleges the doors presence. 

    I've tried offsetting the y-coordinate because I thought maybe the sword gets stuck behind the door, but that isn't it.


    Newbie

    9 Posts

  • #5, by esmeraldaThursday, 17. July, 16:10 Yesterday
    You are welcome :-)

    I bet that is down to the object center of the door.

    Characters have an animation center that defines the position the characters are at in the scene. I assume you have set the center for the sword at the tip of the blade.
    For objects you get an object center - which is represented with a line on the y-axis.
    The position on the y-axis tells the engine what is layered above/below what.
    So the door needs to have an object center smaller (higher up in the scene) than the position of the character to be behind it. And additionally you need to press the little icon with the two arrows to sort the scene objects according to their object center, else you get strange layering results.

    Here is some information about it. Scroll to "The object in 3D space".
    https://wiki.visionaire-tracker.net/wiki/Scenes_and_Objects

    Key Killer

    541 Posts

  • #6, by guusThursday, 17. July, 20:31 Yesterday
    Wonderful! You're a life saver. Thanks again!

    Newbie

    9 Posts

Write post