Need A Tiny Code For Enabled Input

Discussion in 'How Can I...?' started by Bluemusic, Nov 30, 2020.

  1. Bluemusic

    Bluemusic Boxer

    Joined:
    Apr 7, 2020
    Messages:
    59
    Likes Received:
    10
    Hi.
    I need the "Is Touched" node to be enabled with an input so I can get it to do active / non active.
    I´m sure it´s just to make an input, label it Enabled and then a tiny code, but have no idea on to how write the coding.

    I looked into other nodes that has this code like Touch node but I can´t get it to work.

    Anyone?
     
  2. AppNasty

    AppNasty Miniboss Boxer

    Joined:
    Apr 14, 2016
    Messages:
    1,484
    Likes Received:
    890
    Explain what you're trying to do a bit more detailed, please.
     
  3. Bluemusic

    Bluemusic Boxer

    Joined:
    Apr 7, 2020
    Messages:
    59
    Likes Received:
    10
    Hi and thanks for the reply.
    I need to add the code inside is touched to give the node an enable input so I can activate it with an if collide or other. Atm it is activated all the time.
     
    Jackazoid likes this.
  4. AppNasty

    AppNasty Miniboss Boxer

    Joined:
    Apr 14, 2016
    Messages:
    1,484
    Likes Received:
    890
    It would help if i know what youre trying to achieve in the game. What do you want to happen? I know what youre saying you need so you can do whatever it is....but WHAT is it? If i know that, i am confident i can figure out how to achieve it. You are requesting code to be added but a lot of times thats not needed and theres another way to do it. So explaining what it is youre doing in the game will help me.
     
  5. Bluemusic

    Bluemusic Boxer

    Joined:
    Apr 7, 2020
    Messages:
    59
    Likes Received:
    10
    Hi:)
    IMO, there is no good way to enable nodes in Buildbox, like on / off.
    Let´s say you want a button that is turned on during gameplay and when its turned on you can touch it 1 time and then its turned off again (like a panic button).
    I am able to do that with using a statemachine and a UI button (since it has an input enable) but then I need to have a button on the UI which I really don´t want to have since its a hassle when exporting for Iphone vs Ipad (misplacement)

    It would be much simpler and better to use global counter to activate the "is touched node" (which don´t have an input) and after 1 touch its de-enabled.

    Btw, if you are good at coding a lot of users are looking to get a point multiplier node for double ups.
    Example:
    After X amount of points multiply points by X
    After Y amount of points, multiply points b Y
    Also need a reset pin for the whole thing that can be activated by and if collide or similar

    This way we can make 2X, 4X, 6X points, and so forth

    Let me know if any of this is doable App Nasty:)
     
    AppNasty likes this.
  6. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    here you go. @AppNasty he was trying to enable or disable the is touch so it won't be triggered at any point just in specific scenarios. Although I think this is not the right way to pair it with if collide nodes it might work as intended up to a point.

    Below you have the code that you requested:

    Code:
    ///
    let lastSig = false;
    let enabled = false;
    function init() {
        this.enableTouch();
        let mode = this.attribute('Mode');
        let ent = this.entity();
        let cam = ent.camera();
        let touchTestFunc;
    
        if (mode == 'kAABB') {
            touchTestFunc = function (pt) {
                if(!enabled)
                    return;
                   
                let aabb = ent.worldAABB();
                let ray = cam.screenRay(pt);
                let result = ray.intersectsAABB(aabb);
                // log('aabb', result.hit, result.distance);
                let isTouched = result.hit;
                if (isTouched != lastSig) {
                    this.emitSignal('Touched', isTouched);
                    lastSig = isTouched;
                }
            };
        } else if (mode == 'kRaycast') {
            touchTestFunc = function (pt) {
                if(!enabled)
                    return;
               
                let ra = cam.screenRay(pt);
    
                let to = new Vec3(
                    ra.origin.x + (ra.direction.x * 100),
                    ra.origin.y + (ra.direction.y * 100),
                    ra.origin.z + (ra.direction.z * 100));
    
                let rtst = this.scene().physicsWorld().rayTest(
                    ra.origin, to, ent
                );
            let isTouched = rtst.bodies.length > 0;
            if (isTouched != lastSig) {
                    if(!enabled)
                        return;
                   
                    this.emitSignal('Touched', isTouched);
                    lastSig = isTouched;
                }
            }
        }
    
        component.touchBegan = touchTestFunc;
        if (this.attribute('Send On Move')) {
            component.touchMove = touchTestFunc;
        }
    }
    
    function start() { }
    
    function update(dt) { }
    
    function signal(name, value) {
        if (name == 'Enabled') {
            enabled = Math.abs(value) == 1;
        }
    }
    
    component.touchBegan = function () { }
    
    component.touchMove = function () { }
    
    component.touchEnded = function (pt) {
        if(!enabled)
            return;
           
        this.emitSignal('Touched', false);
        lastSig = false;
    }
     
    AppNasty likes this.
  7. AppNasty

    AppNasty Miniboss Boxer

    Joined:
    Apr 14, 2016
    Messages:
    1,484
    Likes Received:
    890
    I wonder if SWITCH node would be useful as well? Awesome job VLAD. Hopefully it is exactly what he needs.
     
  8. Bluemusic

    Bluemusic Boxer

    Joined:
    Apr 7, 2020
    Messages:
    59
    Likes Received:
    10
    Hurray! I have friends in the universe! This worked perfect:) Thanks a lot to both involved!
    Really appreciated this:)
     
    AppNasty likes this.
  9. AppNasty

    AppNasty Miniboss Boxer

    Joined:
    Apr 14, 2016
    Messages:
    1,484
    Likes Received:
    890
    Question. Is this useful for a RECEIVE node? For example i have a UI button with a SEND node linked to an IS TOUCHED node. Then i place a RECEIVE node in object that connects to a random color change node. Can i use this touch node instead? I added "Enabled" and pasted the code in but when connected to a receive node nothing happens.
     
  10. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    Make sure your output is named Touched and not out
     
  11. AppNasty

    AppNasty Miniboss Boxer

    Joined:
    Apr 14, 2016
    Messages:
    1,484
    Likes Received:
    890
    On left side i have Enabled and right is Touched. Maybe i did it wrong. Also all i did was delete all code from an IS TOUCHED node and pasted yours in.
     
  12. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    Do you also have the aabb and raycast Dropdown?
     
  13. AppNasty

    AppNasty Miniboss Boxer

    Joined:
    Apr 14, 2016
    Messages:
    1,484
    Likes Received:
    890
    Yes. All settings are there as i just erased all code from a normal IS TOUCHED node and replaced it with your code.
     
  14. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    Hmm I'll have to check it when I'm home. I git no suggestions as of yet
     

Share This Page