Tutorial Bb3 : How To Set And Load Checkpoint Without Reset Score.

Discussion in 'Buildbox General Discussion' started by mohamed awad, Feb 25, 2020.

  1. badrgfx

    badrgfx Boxer

    Joined:
    Feb 8, 2020
    Messages:
    18
    Likes Received:
    2
    and this for the UI object checkpoint
     

    Attached Files:

    Last edited: Apr 20, 2020
  2. badrgfx

    badrgfx Boxer

    Joined:
    Feb 8, 2020
    Messages:
    18
    Likes Received:
    2
    by the way tha character move on the path but my problem that I can move it right or left
     
  3. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    542
    Likes Received:
    340
    Yep, that should do tge job if you send it from chepoint load
     
  4. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    542
    Likes Received:
    340
    You can use a posituin limiter to limit the left and right issue
     
    badrgfx likes this.
  5. badrgfx

    badrgfx Boxer

    Joined:
    Feb 8, 2020
    Messages:
    18
    Likes Received:
    2
  6. badrgfx

    badrgfx Boxer

    Joined:
    Feb 8, 2020
    Messages:
    18
    Likes Received:
    2
    after load checkpoint the character move in the path but can't turn right or left
     
  7. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    542
    Likes Received:
    340
    Hey, I spend some time investigating your issue and I found few things that are caused by this checkpoint system after load:
    - The shape of the object resets itself to 1,1,1 so this is the reason why you see a bigger square
    - The Physics type is set to Static so you need to set it back to kinematic for some reason
    - The scale for physics shape & if colliders is set to 1,1,1 so again you need to set them both based on your setup.
    - The touch node seems to lost it's pathWidth (is set to 0) due to checkpoint system so that's the reason why you cannot move left or right

    So how do we fix all of this?
    For the first 3 issues you need to add the following line of codes at the end of your init function. Please note that this is based on your template so any values set here should be changed based on your own needs or you can recreate the game keeping in mind that your character scale and physic related objects are set to 1 after load.
    Code:
       
        this.entity().setScale(0.313,0.313,0.313);   
        phys.setShapeScale(0.313,0.313,0.313);
        phys.rebuildShape();
       
        let col = this.entity().component("If Collide");
        log(col.shapeScale());
        col.setShapeScale(0.313,0.313,0.313);
        col.rebuildShape();
    What about the last issue?
    The last issue has multiple solutions but I chose to update the pathWidth data on touch Began function to make sure it is always grater than 0 and is calculated with the initial formula (2*pathSize)
    Code:
          if(pathWidth <= 0){ // After checkpoint reload the pathWidth is zero
            pathWidth = 2 * path.pathSize().x;
        }
     
    badrgfx and Sean Buildbox like this.
  8. badrgfx

    badrgfx Boxer

    Joined:
    Feb 8, 2020
    Messages:
    18
    Likes Received:
    2
    Hey thank you so much for your time, I understand now the issue but about the solution do I need to put the code on the path move node ?
    I put like the image below but not work can you please told what I forget to do ?
     

    Attached Files:

  9. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    542
    Likes Received:
    340
    You forgot to add the condition to "Touch began" function. So currently your object is reseize but you cannot move left or right after checkpoint's load.
     
  10. badrgfx

    badrgfx Boxer

    Joined:
    Feb 8, 2020
    Messages:
    18
    Likes Received:
    2
    hey but I already have the condition if(pathWidth <= 0) in the touchBegan function? maybe I didn't get you
    I will be grateful to you if you put the changes on the BBdoc and upload for me, and thank you so much for your help
     
  11. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    542
    Likes Received:
    340
    Hey there, I do nto encourage the "help me and thanks without learning thing" but for now... I think I would make an exception.

    Here is the Path Move node from Character:

    Code:
    //
    let enabled = false;
    
    let pathPosX = 0;
    let height = 0;
    let jumping = false;
    let jumpForce = 0;
    let calcHeight = 0;
    let sens;
    let gravityY;
    let path;
    let pathWidth;
    let ptPrev;
    
    function init(){
    
        this.enableTouch();
        this.scene().path().setAutoPositionUpdate(false);
        height = this.attribute('Height Over Path');
        sens = this.attribute('Sensitivity') / 50.0;
        gravityY = 0.1 * this.scene().gravity().y;
        path = this.scene().path();
        pathWidth = 2 * path.pathSize().x;
        pathPosX = 2 * this.attribute('Starting Position');
        pathPosX = Math.min(Math.max(pathPosX, -pathWidth), pathWidth);
    
        let phys = this.entity().physics();
        if(phys && phys.type() == 'kDynamic'){
            warning('Path Move Node is designed to work with Kinematic or non Physics objects');
            phys.setType('kKinematic');
        }
       
        this.entity().setScale(0.313,0.313,0.313);   
        phys.setShapeScale(0.313,0.313,0.313);
        phys.rebuildShape();
       
        let col = this.entity().component("If Collide");
        log(col.shapeScale());
        col.setShapeScale(0.313,0.313,0.313);
        col.rebuildShape();
    }
    
    function update(dt) {
        // if (!enabled) return;
    
        jumpForce += dt * gravityY;
        jumpForce = Math.max(-1, jumpForce); //limit falling speed
        calcHeight = Math.max(height, calcHeight + jumpForce);
    
        let ap = path.anchorPosition();
        let arq = path.anchorRotationQuat();
        let mt = Mat4.createTranslation(ap.x, ap.y, ap.z);
        let mr = Mat4.createRotation(arq);
        let m = Mat4.multiply(mt, mr);
        //log(pathPosX);
        let p = new Vec3(pathPosX, calcHeight, 0);
        p = Mat4.transformPoint(m, p);
    
        this.entity().setPosition(p.x, p.y, p.z);
        this.entity().setRotationQuat(arq);
    }
    
    
    function signal(name, value) {
        if (name == 'Enabled') {
            // enabled = value;
    
            if (value) {
                this.scene().setSpeed(this.attribute('Speed'));
            } else {
                this.scene().setSpeed(0);
            }
        } else if (name == 'Jump' && value) {
            jumpForce = 0.1 * this.attribute('Jump Force');
        }
    }
    
    component.touchBegan = function (pt) {
        if(pathWidth <= 0){
            pathWidth = 2 * path.pathSize().x;
        }
        ptPrev = pt;
    }
    
    component.touchMove = function (pt) {
        pathPosX += (pt.x - ptPrev.x) * sens;   
        pathPosX = Math.min(Math.max(pathPosX, -pathWidth), pathWidth);
        ptPrev = pt;
    }
    
    component.touchEnded = function (pt){}
    please let me know the results. Another reason that I have is that I work on latest beta build version so even if I send you the bbdoc it wont be compatible with your version since you use release or 3.1.3
     
    badrgfx likes this.
  12. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    542
    Likes Received:
    340
    oh btw you forgot to add "ptPrev = pt; " in your component.touchBegan function. this is very important to this system since that's the initial point of the object and without that the system cannot see/know how to react.
     
    badrgfx likes this.
  13. badrgfx

    badrgfx Boxer

    Joined:
    Feb 8, 2020
    Messages:
    18
    Likes Received:
    2
    Thank you sooo much for your effort now it works after adding ptPrev = pt;
     
  14. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    542
    Likes Received:
    340
    You are welcome! I hope you learn something out of this :D, stay awesome and have fun!
     
    badrgfx likes this.
  15. Serdar

    Serdar Boxer

    Joined:
    Apr 5, 2020
    Messages:
    27
    Likes Received:
    2
    Hi all, @mohamed awad

    Thanks for your tutorial. it works. but something's wrong :)
    My point 10 before defeat. and I starting from the checkpoint after defeat.
    But my game point is wrong, it should be 10. but it's 16 or 18 .

    I am sure. every step is true. but whats wrong ? :eek::eek:
     
  16. Serdar

    Serdar Boxer

    Joined:
    Apr 5, 2020
    Messages:
    27
    Likes Received:
    2
    for example I earn 10 coins in checkpoint1 . After than defeat.
    When I start again, my coin is 20(should be 10).
    I defeat again without new earn coin. each start automatclly 30 .. 40 .. 50, etc. (still should be 10)
     
  17. mohamed awad

    mohamed awad Avid Boxer

    Joined:
    Mar 10, 2019
    Messages:
    305
    Likes Received:
    158
    It's not random scores, it's best scores on this scene,
    When restart your game you should have reset all local score
    Every button on your game over UI (except restart checkpoint button) should reset your local score to make sure that the player will reset the score whatever button he will pressed
     
  18. Serdar

    Serdar Boxer

    Joined:
    Apr 5, 2020
    Messages:
    27
    Likes Received:
    2
    I have only 2 button in my game over UI. and use reset func. (except restart checkpoint button)
    like your tutorial
     

    Attached Files:

    Last edited: May 6, 2020
  19. Serdar

    Serdar Boxer

    Joined:
    Apr 5, 2020
    Messages:
    27
    Likes Received:
    2
    I delete this lines in checkpoint loader node(default codes). it's done.

    if (checkpoint.points !== undefined) {
    this.scene().setScorePoint(checkpoint.points);
    }
     
    mohamed awad likes this.
  20. mohamed awad

    mohamed awad Avid Boxer

    Joined:
    Mar 10, 2019
    Messages:
    305
    Likes Received:
    158
    excellent,i'm glad you solve it
     

Share This Page