Sling Node In Bb3 2d World

Discussion in 'Buildbox 3.0' started by mmicoe, Dec 30, 2020.

  1. mmicoe

    mmicoe Avid Boxer

    Joined:
    Dec 20, 2016
    Messages:
    148
    Likes Received:
    41
    I am using the sling node in 2D world mode but it does not work as I would like. I have made some modification in the code and thus it deletes the source object every time it is launched but I don't like it for technical reasons. By default the sling node launches the projectile but it does so from a starting point that is always the same and makes a copy. I need the sling to work like a billiard ball, that is, you can continuously throw it and it moves. And remove it as I want! Anyone who has the solution?

    Now what I do is sloppy. I get the identity of the object xx=this.entity(); and when I release the sling, I delete the object xx.remove(); This implementation is not very feasible because the instance of the object starts every time and I lose every time I restart it all the variables


    Thanks,
    Mauro
     
    Last edited: Dec 30, 2020
  2. mmicoe

    mmicoe Avid Boxer

    Joined:
    Dec 20, 2016
    Messages:
    148
    Likes Received:
    41
    Hi all,
    SOLVED:
    I update the Sling Shot Node:
    the problem is the scene.create(projectileAsset);

    On function fire(), scene.create(projectileAsset), it creates a new entity each time the sling is pressed, and it is the problem because the entity is a new object with a new id each time:

    projectile = scene.create(projectileAsset);
    projectile.setPosition(entPos.x,entPos.y,entPos.z);

    Steps to solve it:
    1. For the sling to behave differently, it is necessary to modify these two lines of code by the source entity.
    2. Create a new vector for the main entity to get the velocity.x, y and z.
    3. Update the function update(dt) {... to the main entity.

    Now, the sling can be executed whenever desired with the same entity. And since the entity is not created every time, the variables can be used correctly because the entity is not deleted every time.

    All the best,
    Mauro
     
    Vlad-NY likes this.

Share This Page