Results 1 to 11 of 11

Thread: Triggering TTS objects inside an Assetbundle and triggering effects of an Assetbundle

  1. #1

    Triggering TTS objects inside an Assetbundle and triggering effects of an Assetbundle

    I have a dice tray Unity asset.

    What I would want to do:

    The following things would be nice, if possible.
    1. Clicking the dice tray, or some part of it, to make all dice inside of it do a "Roll".
    2. Would be nice if that same click could be able to trigger a particle effect of the dice tray itself.

    I think these should be doable with the latest version of TTS?

    Now, I'm not hoping anybody to code or do anything for me, just asking if there already is something similar in Steam workshop?
    Hopefully something so easy that a LUA noob could investigate and figure out what is happening...

    T:T

  2. #2
    Join Date
    May 2016
    Posts
    1,072
    1. You could hide a button inside the base of the tray so if they click on the center of it, it would hit that button, triggering code. That bit is easy enough.

    If you intend to do a roll, the scripting is quite simple (as far as the ideas behind it). When they click the button, you use getAllObjects(), then run a for loop through the table it gives you. Have it check each entry in table for its .tag field. I think all dice and custom dice should come up as "Dice" but you could do tests to be sure. Then subtract the X and Z of the dice from the X and Z of the tray's position, and if it is within a certain X/Z (say, 4 units) then you know the die is in the tray and can be rolled. Then use roll() on them.

    2. As long as the particle effect is a trigger, it is super easy to trigger it on each button press.

    I was actually intending to do something like this (well, part 1 anyway). To my knowledge nothing like this exists currently. So if you WERE looking for somebody to do the coding, I could do it. If you can make the dice tray and the assetBundle effect that goes with it. If you're interested, add me on steam. [url]http://steamcommunity.com/id/MrStump/[/url]

  3. #3
    1. You could hide a button inside the base of the tray so if they click on the center of it, it would hit that button, triggering code. That bit is easy enough.
    I used a stripped down version of your spiffy Buzzer Script applied just like this to do some basic tests on triggering simple assetbundle animations . . . Works like a charm.

    [url]http://steamcommunity.com/sharedfiles/filedetails/?id=776802982&searchtext=buzzer[/url]



  4. #4
    Join Date
    May 2016
    Posts
    1,072
    Haha thank god you could make it work. Those buttons look amazing BTW.

  5. #5
    The plunger which goes up and down holds the triggers and your button script in this setup.

    Interestingly One thing I have found which I was not expecting, is scripting buttons don't track with animations even when the assetbundles are set to animate physics so a little careful placement was needed to keep the button inside the animations range of motion..

  6. #6
    Quote Originally Posted by MrStump View Post
    [...]When they click the button, you use getAllObjects(), then run a for loop through the table it gives you. Have it check each entry in table for its .tag field. I think all dice and custom dice should come up as "Dice" but you could do tests to be sure. Then subtract the X and Z of the dice from the X and Z of the tray's position, and if it is within a certain X/Z (say, 4 units) then you know the die is in the tray and can be rolled. Then use roll() on them.
    It'd probably be much easier to just spawn a scripting zone inside the tray. Avoid looping every object on the table and no need to compare positions manually. Something like:
    Code:
    function buttonClicked()
      pos = self.getPosition()
      pos.y = pos.y + 1
      zoneSpawn = {position = pos
             , scale = { 4, 1, 4 }
             , type = 'ScriptingTrigger'
             , callback = 'zoneCallback'
             , callback_owner = self
             , rotation = self.getRotation }
      spawnObject(zoneSpawn)
    end
    
    function zoneCallback(zone)
      for o in zone.getObjects()
        if o.tag == 'Dice'
          o.roll()
        end
      end
    
      zone.destruct()
    end
    I wrote that mostly from memory and haven't tested it, so be aware you may need to tweak a bit. For a working example check out the [URL="http://steamcommunity.com/sharedfiles/filedetails/?id=649618762"]dragonlance mod on the workshop[/URL]. Neither the mod nor original script is mine, I adjusted their script to move the dragons up when the bases grow and send the bases back home (positioned in a neat row) when they would shrink to 0 and they were kind enough to incorporate the changes into the mod.

    Also, you'd have to change the exact numbers for the zone's scale and Y position based on the dimensions of the tray. Of course it's only going to work fully for a rectangular tray, but you could theoretically spawn additional smaller zones to fill in a different shape bit by bit. Might hit the same die twice if it ends up being on an edge between two zones, but if you're just rolling it that shouldn't matter.

  7. #7
    Join Date
    May 2016
    Posts
    1,072
    Personally I would probably go the scripting zone route. But assuming people move the trays, the script would need to spawn it, which is a bit tricker for people inexperienced with scripting I estimate. But with your script they should be able to manage it without any issue =)

    If people re-size the tray, it could cause issues. When the tray is at its default size (scale 1, 1, 1) you could figure out how big the zone has to be. And establish scaleX = self.getScale().x right after you establish pos. Then when you are making scale, simply make it scale = {4*scaleX, 1, 4*scaleX} with the 4/1/4 being replaced by whatever dimensions you figured out. That way, if they double the size of the tool, the scripting zone will be good still.

    Given the context, you COULD multiply the y by the scale factor as well, but you are probably fine without doing that.

  8. #8
    Thanks guys, You gave me a lot to think about.
    I'll be away for the next week, but will definitely check on your suggestions after that.

    Just to make it clear to me, what is a "button"?
    Is it a virtual entity in Lua code that I can somehow "hide" in my tray?
    Or are we talking of an actual physical button mesh that I am to copy from some steam workshop project?
    I rather not add any extra meshes, was just hoping that the tray object or one of the objects it consists of, could act as this "button".

    Identifying dice
    Rolling ALL dice on the table doesn't work, sorry.
    Needs to be just those inside the dicetray....
    Maybe I could check the location of all dice? But Roll just those that are close enough to the location of the dice tray itself?
    Will test this...

    Resizing and moving
    Resizing is not an issue.
    As it works now. Resizing Assetbundles with effects doesn't work correctly at the moment in TTS (haven't tested it in latest TTS version).
    So, I will worry about that later.

    Moving is necessary.
    The tray must be movable.
    But I think it should be possible if I identify the rollable dice by comparing to the location of tray itself?

    Triggering effects
    Thanks guys for the suggestions.
    Will check those out.

  9. #9
    @MrStump
    I am first and foremost doing this to learn something new, so I'll probably first try to do it myself.
    However, my time is very limited, and if it seems that I will not be able to cobble it together in a reasonable amount of time, I'll be more than honored if you could help me.

    Just let me have a quick go at it first.

    Meanwhile, you are free to experiment with my Scifi dicetray. [url]http://steamcommunity.com/sharedfiles/filedetails/?id=768600239[/url]
    I'm afraid that there are no triggerable effects there yet, but that might change next week..

    Also, happy to accept you as a Steam friend.

  10. #10
    Once again I call upon the mighty forces of the Community!
    Did my button, did my dice detection and did my roll code(all hail Mr Stumps Function helper article [url]http://steamcommunity.com/sharedfiles/filedetails/?id=752690530[/url])

    But then, the really tricky part...
    Created effect -> added trigger script -> generated asset bundle -> created a trigger call code ( all hail Mr...) -> Tested -> Nothing happens.

    The code recognizes the trigger and starts it. But nothing happens.
    The effect works, as I checked the "Play on awake" and it plays once, as it should.

    I can only assume my trigger in unity is no-go.

    Tried to study the Light and Explosion triggers that exist, but the jscript component in them looks different(?).
    Oh, what to do, what to do?

    Included a couple of pics of my attempt on asset bundle trigger.
    Maybe I got it completely wrong?
    cap2.jpgcap1.JPG

  11. #11
    Endig this thread here. Continuing elsewhere.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •