Smart Ui Elements In Bb3

Discussion in 'Technical Discussion' started by jmiller8031, Jul 29, 2018.

  1. jmiller8031

    jmiller8031 Avid Boxer

    Joined:
    Feb 23, 2018
    Messages:
    218
    Likes Received:
    82
    I'm just experimenting. I figured out a way to turn any 3D object into a UI button. This would allow one to do anything they wanted with buttons. Idle clicker, quiz app, whatever. It's just a single custom node. You can see the code below and the node layout.

    In this example you click on the 3D object and it just increases the score.
    Screen Shot 2018-07-29 at 7.44.03 PM.png
    Screen Shot 2018-07-29 at 7.44.48 PM.png

    Here is the code in text form so you don't have to retype it.

    Code:
    var _enabled = false;
    var _hit = false;
    
    //----Standart
    function init(){
        this.emitSignal('Touched', false);
        this.enableTouch();
    }
    function update( dt ){
    }
    function signal( name, value){
        _enabled = value;
    }
    
    //----Touches
    function touchBegan( point ){
        let _startPoint = point;
       
        let wp = this.scene().screenToWorld(_startPoint.x,
                                            _startPoint.y);
        vecWP = new Vec3(wp.x, wp.y, wp.z);
       
        let pos = this.entity().position();
        vecPos = new Vec3(pos.x, pos.y, pos.z);
       
        if(vecWP.distance(vecPos) <= 1.5){
            this.emitSignal('Touched', true);
            _hit = true;
            log('Hit ' + _hit);
        }
        else{
            log('Hit ' + _hit);
        }
           
    }
    component.touchBegan = touchBegan;
    
    function touchEnded(){
        if(_hit){
            this.emitSignal('Touched', false);
            _hit = false;
        }
    }   
    component.touchEnded = touchEnded;   
        
    You may or may not have to increase or decrease the size of the vector comparison in the if statement depending on the size of the 3D object.
    This line here is what I mean, I have it set to 1.5.
    Code:
    if(vecWP.distance(vecPos) <= 1.5)
    
     
    adrogdesigns and rcantone like this.
  2. Zohra

    Zohra Boxer

    Joined:
    Jul 26, 2018
    Messages:
    2
    Likes Received:
    0
    Pretty cool, I can see good use for this,
     
  3. PLASSA

    PLASSA Boxer

    Joined:
    Jun 5, 2018
    Messages:
    24
    Likes Received:
    6
    Great work werewoodle!

    Here's a video preview from the discord:
     
  4. wesam_badr

    wesam_badr Miniboss Boxer

    Joined:
    Oct 10, 2015
    Messages:
    1,065
    Likes Received:
    479
    Nice I love it, how to make that touched button I didn't find it anywhere.
     
    Last edited: Jul 30, 2018
  5. gauravdashora676

    gauravdashora676 Boxer

    Joined:
    Sep 25, 2015
    Messages:
    12
    Likes Received:
    2
    When two 3d objects are placed in the same scene then how to select an individual object in the same scene?
     
  6. mxstudios

    mxstudios Boxer

    Joined:
    Aug 30, 2016
    Messages:
    51
    Likes Received:
    13
    This is cool. But there is no way to make it stay on the screen when world moves, right?
    I am trying to make a joystick, and can't figure out best way.
     

Share This Page