How to attach a png image to the character?

  • #1, by AkcayKaraazmakThursday, 30. April 2015, 14:10 10 years ago
    Hi guys, I have an idea to solve the shadow problem for the 3d character. I want to make png image for character shadow and put it under the character feet and make it move when the character walks. How I can position the shadow png to the character and make it follow the characters walking?

    Cheers

    Great Poster

    440 Posts


  • #2, by afrlmeThursday, 30. April 2015, 15:45 10 years ago
    Are you talking about a simple shadow shape or an animated shadow that mirrors what the character is doing?

    If it's the simple shadow shape (blob thing) then it would be easy enough to do with a small loop, to update the shadow image (animation would work best or a character) position to that of the character minus a few pixels or so to make sure it is layered beneath the character (character method).

    1. create a new character. name it something like hero_shadow. & add some animation frames to the idle (standing) animation sections.

    2. Define the animation center, so that the shadow will end up where the characters feet are.

    3. Set the characters starting point to the same as where your playable characters starting point is.

    4. Create a new script & make sure it is set as a definition script. Add the code block below to it... (adjust as needed).
    -- * variables * --
    local pos, scn -- empty variable (will be used to store current characters position)
    
    -- * function that will be used to update shadows position * --
    function updateShadowPos()
     scn = game:getLink(VGameCurrentScene):getName()
     -- + --
     if scn == getObject("Game.GameCurrentCharacter.CharacterScene"):getName() and scn == getObject("Characters[hero_shadow].CharacterScene"):getName() then
      pos = getObject("Game.GameCurrentCharacter"):getPoint(VCharacterPosition)
      -- + --
      getObject("Characters[hero_shadow]"):setValue(VCharacterPosition, { x = pos.x, y = (pos.y - 10) })
     end
    end
    
    registerEventHandler("mainLoop", "updateShadowPos") -- create loop event
    


    ... the loop should only work if both the shadow & currently active character are both on the currently active scene.

    Imperator

    7285 Posts

  • #3, by AkcayKaraazmakThursday, 30. April 2015, 15:52 10 years ago
    Now I gonna try and report you back bro. Thak you so much!!!!!

    Great Poster

    440 Posts

  • #4, by AkcayKaraazmakThursday, 30. April 2015, 16:07 10 years ago
    Hey mate, you are the hero! It worked and very nicely fallow the character. Just I need to work more and the graphics of the shadow to make it match with the char. Thank you so much bro, you are great!

    Great Poster

    440 Posts

  • #5, by afrlmeThursday, 30. April 2015, 17:30 10 years ago
    The good thing about using a character is that it will automatically scale like the character too, so you just need to get the animation center for the shadow correct to make it snap to the correct position. It might be an idea to create a few variation animation frames if you want the shadow to look more dynamic.

    P.S: you need to remember to set the shadow character to the same scene as the character when you change scenes. Alternatively you could add an if query to the script to automatically update shadow characters scene value if it is not the same as the current characters.
    -- * variables * --
    local pos, scn -- empty variable (will be used to store current characters position)
    
    -- * function that will be used to update shadows position * --
    function updateShadowPos()
     scn = game:getLink(VGameCurrentScene):getName()
     -- + check & update shadow scene + --
     if getObject("Characters[hero_shadow].CharacterScene"):getName() ~= getObject("Game.GameCurrentCharacter.CharacterScene"):getName() then
     getObject("Characters[hero_shadow]"):setValue(VCharacterScene, getObject("Game.GameCurrentCharacter.CharacterScene"))
     end
     -- + update shadow position + --
     if scn == getObject("Game.GameCurrentCharacter.CharacterScene"):getName() and scn == getObject("Characters[hero_shadow].CharacterScene"):getName() then
      pos = getObject("Game.GameCurrentCharacter"):getPoint(VCharacterPosition)
      -- + --
      getObject("Characters[hero_shadow]"):setValue(VCharacterPosition, { x = pos.x, y = (pos.y - 10) })
     end
    end
    
    registerEventHandler("mainLoop", "updateShadowPos") -- create loop event
    


    P.P.S: I wrote the code in old longhand because not all of the new shorthand script works in the current public build.

    Imperator

    7285 Posts

  • #6, by AkcayKaraazmakFriday, 01. May 2015, 11:08 10 years ago
    This is great mate! Thank you so much! . A one more boring question if you dont mind smile ... After your solution, I've planned to make different dynamic shadow shapes according to each scene angle. So I will have different shadow_characters for the each scene. I'll make them ready in the characters tab. Lets say, scn_01_sh, scn_02_sh ... .. And when the character goes for a new scene, how I will change the shadow_character. Lets say char goes from scn_1 to scn_2 . So how to unload scn_01_shd and load scn_02? smile

    Thank you bro

    Great Poster

    440 Posts

  • #7, by afrlmeFriday, 01. May 2015, 12:48 10 years ago
    Ah might be best to use the first script version I provided then. You could create another small function for it which you could use to define the shadow.

    -- * variables * --
    local pos, scn -- empty variables
    local shdw = "hero_shadow" -- add the initial shadow character's name here
    
    -- * function that will be used to update shadows position * --
    function updateShadowPos()
     scn = game:getLink(VGameCurrentScene):getName()
     -- + --
     if scn == getObject("Game.GameCurrentCharacter.CharacterScene"):getName() and scn == getObject("Characters[" .. shdw .. "].CharacterScene"):getName() then
      pos = getObject("Game.GameCurrentCharacter"):getPoint(VCharacterPosition)
      -- + --
      getObject("Characters[" .. shdw .. "]"):setValue(VCharacterPosition, { x = pos.x, y = (pos.y - 10) })
     end
    end
    
    -- * function that will be used to set the shadow character & outfit * --
    function defineShadow(c, o)
     shdw = getObject("Characters[" .. c .. "].CharacterOutfit[" .. o .. "]")
    end
    
    registerEventHandler("mainLoop", "updateShadowPos") -- create loop event
    


    Quick question: do you not think it would be more beneficial to use the same shadow character, but create multiple outfits for it? Less hassle than creating loads of characters.

    Anyway... To use the updated script I just provided...

    1. define the hero characters name where it says: local shdw =

    2. to update the shadow character & outfit you just need to create an execute a script action part at the beginning of each scene where you want to change the shadow character & or outfit containing something like...
    defineShadow("character_name", "outfit_name") -- names are case sensitive
    


    Ok?

    Imperator

    7285 Posts

  • #8, by AkcayKaraazmakFriday, 01. May 2015, 13:05 10 years ago
    Lee yes yes mate as you said, just 1 shadow character and different outfiths for the scenes angles smile ... So can I use your last script for chaning the outfiths of the shadow character?

    Great Poster

    440 Posts

  • #9, by afrlmeFriday, 01. May 2015, 13:21 10 years ago
    Yes.

    Just create the execute a script action I mentioned at the beginning of each scene.

    P.S: remember that names (objects, characters & animations etc) are all case sensitive. So if a character is called tom then it is written as tom. If it is called Tommy Tucker, then it is written Tommy Tucker. If you join the words up with -dash or _underscores then they also need to included & so on.

    Imperator

    7285 Posts

  • #10, by AkcayKaraazmakFriday, 01. May 2015, 13:29 10 years ago
    Thank you so much Lee!!! You are grate!

    Great Poster

    440 Posts

  • #11, by afrlmeFriday, 01. May 2015, 14:57 10 years ago
    Very nice, I've always wanted to be a grate, just not sure which definition I would rather be. grin

    Imperator

    7285 Posts