Physic Fail

Discussion in 'Buildbox 3.0' started by NeedSomeHelp, May 21, 2019.

  1. NeedSomeHelp

    NeedSomeHelp Boxer

    Joined:
    Dec 4, 2018
    Messages:
    69
    Likes Received:
    5
  2. PunkPuffin

    PunkPuffin Avid Boxer

    Joined:
    Sep 27, 2018
    Messages:
    285
    Likes Received:
    195
    I can tell you why but not the cause. If you put the game in debug mode you will see that when your character moves left or right the sphere collider doesn't move with it. That is your problem. Move the cubes to the centre and it does bounce off it. Something in your movement is not jelling with the physics and collider
     
  3. imonedesign

    imonedesign Boxer

    Joined:
    Oct 25, 2015
    Messages:
    73
    Likes Received:
    50
    Try this code instead of the one you have in Controls node:
    -----------------------------------------------------------------------------------------
    var _speed;
    var _enabled = false;
    var _prev;
    var _target;
    var _phys;

    //----Standart
    function init(){
    this.enableTouch();
    _speed = this.attribute('Speed');
    _phys = this.entity().physics();
    }
    function update( dt ){
    let x = this.entity().position().x;
    let delta = x - _target.x*0.02;

    let vel = _phys.linearVelocity();
    vel.x = -delta*20;
    _phys.setLinearVelocity(vel.x, vel.y, vel.z);
    }
    function signal( name, value){
    _enabled = value;
    }
    //----Move
    function move( point ){
    if(_enabled){
    let wp = this.scene().screenToWorld(point.x, point.y);

    _target = new Vec3((point.x-320)*_speed.x,
    0,
    0);

    }
    }
    component.move = move;

    //----Touches
    function touchBegan( point ){
    this.move( point );

    _prev = point;
    }
    component.touchBegan = touchBegan;

    function touchMove( point){
    this.move( point );
    _prev = point;
    }
    component.touchMove = touchMove;

    function touchEnded(){
    }
    component.touchEnded = touchEnded;

    -----------------------------------------------------------------------------------------
     
  4. NeedSomeHelp

    NeedSomeHelp Boxer

    Joined:
    Dec 4, 2018
    Messages:
    69
    Likes Received:
    5
    Thanks a lot imonedesign! It worked
     
  5. imonedesign

    imonedesign Boxer

    Joined:
    Oct 25, 2015
    Messages:
    73
    Likes Received:
    50
    You are welcome :)
     
  6. NeedSomeHelp

    NeedSomeHelp Boxer

    Joined:
    Dec 4, 2018
    Messages:
    69
    Likes Received:
    5
  7. NeedSomeHelp

    NeedSomeHelp Boxer

    Joined:
    Dec 4, 2018
    Messages:
    69
    Likes Received:
    5
    @imonedesign I use your node in a new project in the newest version of BB3. But I get the fail: " _target is undefined." Any ideas?
     

Share This Page