Slingshot Asset / Pool Template (fix)

Discussion in 'BBAssets' started by PunkPuffin, Jun 11, 2019.

  1. PunkPuffin

    PunkPuffin Avid Boxer

    Joined:
    Sep 27, 2018
    Messages:
    285
    Likes Received:
    195
    Hi All,

    I see a few people have said the Slingshot Asset / Pool Template doesn't work

    I'm not exactly sure on how it should have worked as I never saw it when it did but this at least seems to look ok to me.

    Replace the code in the "Slingshot" node with what is here.

    Code:
    var _cue;
    var _line;
    var _arrow;
    var _x=0;
    var _y=0;
    var _hit = false;
    
    //this.ball;
    
    function init(){
        this.emitSignal('Touch', false);
        _cue = this.animation('CueBall');  
        _line = this.animation('CueLine');
        _arrow = this.animation('CueArrow');
      
        this.enableTouch();
    }
    
    function update(dt){
    }
    
    function signal(name, value){
    
    }
    
    function setCuePosition( x, y){
    
        _cue.setPosition(x, 0, y);
    
        v = new Vec3(x, 0, y);
        _line.setPosition(x*0.5, 0, y*0.5);
        var angle = Math.atan2(x, y) * 180/Math.PI;
      
        _line.setRotation(-90, angle, 0);
        var len = Math.sqrt(x*x + y*y);
        _line.setScale(1,len);
    
        _arrow.setRotation(-90, angle, 0);
    
    
        _x = x;
        _y = y;
    }
    component.setCuePosition = setCuePosition;
    
    
    
    //----Touches
    function touchBegan( point ){
        var wp = this.scene().screenToWorld(point.x, point.y);
        wp = new Vec3(wp.x, wp.y, wp.z);
        var pos = this.entity().position();
        pos.y = 0;
        pos = new Vec3(pos.x, pos.y, pos.z);
        if(wp.distance(pos) <= 0.8){
            this.emitSignal('Touch', true);
            _hit = true;
          
            _startPoint = wp;
            this.setCuePosition(wp.x, wp.y)
        }
    }
    component.touchBegan = touchBegan;
    
    function touchMove( point){
        if(!_hit){
            return;
        }
      
        var wp = this.scene().screenToWorld(point.x, point.y);
        wp = new Vec3(wp.x, wp.y, wp.z);
        this.setCuePosition(wp.x, wp.z)
    }
    component.touchMove = touchMove;
    
    function touchEnded(){
        if(_hit){
            let ph = this.entity().physics();
            ph.setLinearVelocity(_x*-2, 0, _y*-2);
        }
        this.emitSignal('Touch', false);
        _hit = false;
    }
    component.touchEnded = touchEnded;  
        
     
    weboha, rjp996tt and wayne_martell like this.
  2. vinoalan

    vinoalan Boxer

    Joined:
    Jun 6, 2019
    Messages:
    4
    Likes Received:
    0
    its not work for me
     
  3. PunkPuffin

    PunkPuffin Avid Boxer

    Joined:
    Sep 27, 2018
    Messages:
    285
    Likes Received:
    195
    Things May have changed since I did this
     
    rizwanashraf likes this.

Share This Page