License from €75
DE EN FR ES IT CZ

Position binding to the character depending on its scale [SOLVED]

This thread is a few years old. Some details may refer to an earlier version of Visionaire Studio. Current tutorials

  1. · 4 years ago
    Hi!

    Can you please tell me if it is possible to attach particles or light sources to a character, regardless of its size in a particular scene? Those. something like:

    local c = Characters["name"]

    shaderActivateLighting(1)
    shaderLamp(0, 1, {1000,500,1}, {0,0,0}, {0.01,0.005,0}, {0,0,0}, {1,1,1}, 1)
    bind("light1", "lights[0].position",
    shaderPoint(inverty(scrollfix(offset(field("Characters.name.Position"),{0+c.Size.x\3, 0+c.Size.y\2}))),10))

    --place a dot in the middle of the character sprite at Y , and 1/3 at X, at any sprite size. The idea is, for example, if the character carries a torch, a lantern, etc.

    Of course, I can assign new bindings from scene to scene, but if there is an easier solution, that would be great. Thank you.
  2. Working on a game?

    The free version covers up to 25 scenes per project. For more scenes and to sell your game, you need a license. Forum readers get the Indie Bundle 15 % off with the code FORUM15: €84.15 instead of €99, valid until 31 Dec 2026.

    Get 15 % off Try it for free
  3. · 4 years ago
    First off, I'm not going to be providing you with a solution as I still haven't learnt how to use the bind() function, I tend to use mainLoop instead if I want to dynamically loop lighting things as I find it much easier to read than the bind function.

    Anyway, I'm just going to break a few things down for you & maybe you will be able to figure out the calculations you need to make to get it to work yourself as math is something I am not very good at.

    game.CurrentCharacter.Size or Characters["Tom"].Size equals the current percentage scale value of the character & not the height & width of the character in pixels, to do that you would use something like this: graphics.getAnimationSize(game.CurrentCharacter).

    game.CurrentCharacter.Position or Characters["Tom"].Position is the coordinate on the character that you defined the animation center, which is usually placed somewhere down near the feet, so you need to take that into consideration when you are wanting to offset from it, especially if the animation center coordinate is not the same value in each of the animations belonging to same character.

    What I believe you actually need to do is figure out the x & y offset value that you would want to use if the character scale was at 100% & then you would do some math calculations against that based on the current character scale to get the adjusted offset, which I think (but I could be wrong - I'm bad at math remember) would be something along the lines of this...
    x = offset x / 100 * character size -- only if you want to offset x
    
    y = offset y  / 100 * character size

    Anyway, I think you should have enough information now to probably figure it out yourself.

    P.S: in regards to particles you should also be able to reposition them with scripting too, but they would be linked to the scene they are assigned to. I don't know if it's possible to change the scene or object they are assigned to.

    local p = graphics.getParticles(game.CurrentScene.Objects["example"])
    
    p.center = {game.CurrentCharacter.Position.x, game.CurrentCharacter.Position.y - 50}


  4. · 4 years ago
    Ok, thanks for the reply, I'll try to figure it out.
  5. · 4 years ago
    Here is a solution that seems to work (in this case, the lamp is in the middle of the game character):

    function name()
    shaderActivateLighting(1)
    local c = game.CurrentCharacter
    shaderLamp(0, 1, {c.Position.x,c.Position.y-c.Size*5,1}, {0,0,1}, {0.0,0.0,0.0005}, {0,0,0}, {1,1,1}, 1)
    end
    registerEventHandler("mainLoop", "name")

    @Afrlme, another question, what command to cancel this action if necessary (exit to the menu, etc.)? shaderDeactivateLighting() does not work in this case. Thanks.
  6. · 4 years ago
    script section: definition type script
    local c = game.CurrentCharacter
    
    
    
    function initLamp()
    
     shaderActivateLighting(1)
    
     registerEventHandler("mainLoop", "Lamp")
    
    end
    
    
    
    function Lamp()
    
     shaderLamp(0, 1, {c.Position.x,c.Position.y-c.Size*5,1}, {0,0,1}, {0.0,0.0,0.0005}, {0,0,0}, {1,1,1}, 1)
    
    end
    
    
    
    function killLamp()
    
     shaderDeactivateLighting()
    
     unregisterEventHandler("mainLoop", "Lamp")
    
    end

    execute a script >

    initLamp() -- start lamp


    execute a script >

    killLamp() -- stop lamp

    The reason it wouldn't end with shaderDeactivateLighting() is because you were turning the lighting back on inside of the function you were looping.
  7. · 4 years ago
    thank you very much
  8. · 4 years ago
    Sorry, updated the killLamp() function. I made a small typo. Was supposed to unregister the loop not register it, oops!
  9. · 4 years ago
    Yes thanks, I figured it out. I just use unregisterEventHandler.

This thread is closed because nobody has replied for more than a year. Feel free to ask your question in a new thread.

New thread

Really delete this post?