Bb3 Pool Preset : Z Axis Issue

Discussion in 'Buildbox 3.0' started by ThomasC, Nov 7, 2018.

Tags:
  1. ThomasC

    ThomasC Boxer

    Joined:
    Nov 8, 2017
    Messages:
    63
    Likes Received:
    26
    Hi forum,

    working in the "pool" preset trying to make a game that has a downward slope. When my character aka slingshot moves to a lower point on the z axis the slingshot mechanism no longer works. I'm sure the answer has lies within the node code posted below, but I've been tinkering with it and cannot find a solution. I basically want the character to still just move on the x and y axis, but still work if the character moves to -2 on the z, as of now it does not.

    If anyone could take a look and give me a helpful hint on why this isn't working it would be greatly appreciated. (I will continue tinkering and will post here if I figure out the problem)

    Thanks

    Screen Shot 2018-11-07 at 8.53.20 PM.png
     
  2. DanFarfan

    DanFarfan Avid Boxer

    Joined:
    Sep 22, 2018
    Messages:
    101
    Likes Received:
    40
    Hi, yes. This came up before. Not sure where in the forums. Someone wanted different "tables" at different heights, but the slingshot only worked on the original table, at the original height. Okay. So, slightly different question, but the solution is the same (I believe).

    Notice the line of code
    if (wp.distance(pos) <= 0.8) {

    What this does is try to detect which ball your click (or press) is in range of.
    Remember there is only one screen, so the code you see relating to touch* is run by ALL the slingshots.
    Okay, so when your press in the 2 D world is found to be super close in the 3D world to (1 or more) slingshots, the act of shooting begins (as signalled by setting the global variable
    _hit = true;

    BUT.. how did we get from 2D to 3D in order to check the distance??

    And the answer is 2 lines up
    pos.y = 0; // in the software biz we call this... hand waving! ;-)

    The example as written assumes the "ground" (i.e. the table) is at or very near the y coordinate 0.
    Whoops. That's not going to be true for a "higher" table (or lower) or for an entire table that slopes.
    Thus, the illusion that the slingshot stopped working. It didn't, but the point on the screen that SEEMS to be within 0.8 is not really close to the ball any more.

    That's enough info for you to create a fix that covers all the different setups you plan on using.

    Good Luck!

    @DanFarfan

     
    ThomasC likes this.
  3. ThomasC

    ThomasC Boxer

    Joined:
    Nov 8, 2017
    Messages:
    63
    Likes Received:
    26
    Awesome, thank you so much @DanFarfan

    I just changed :

    if (wp.distance(pos) <= 0.8) {

    to a larger number and now it seems to work at any point I want on the Z axis.

    I appreciate the quick reply.
    Thank you
     

Share This Page