How do I calculate viewportbottom at zElevation(n)

Not favoritedFavorited Favorited 0 favourites
  • 7 posts
From the Asset Store
Calculate parabolic trajectories and tween objects over them.
  • I'm creating object outside layout bottom of layout ViewportBottom(0) + 200 So we cannot se it being created. then I set its z elevation to int(random(-150,0))

    but in runtime we can clearly see objects are being created. How can I fix it?

  • Set it invisible till you finish positioning it if you do it over multiple frames?

    Or depending on the size of the object you’d need to create it further off screen so it’s not seen.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I'm create object offscreen at bottom and then moving them to upward. either I have to create them far below but then it will take time to appear if objects are less deep Zelevation. I want to know if can create it below visible area even in zelevation.

  • So you want the projected bounding box of the object at different z elevations.

    You may be able to get somewhere with the expressions to convert from a position to a layer.

    Mathematically you should be able to calculate it with the object’s position and the fov of the camera. Basically a 3d projection to the screen if you want to find more info about that online.

    A third way is to just do some trial and error.

    Like set y to y to self.y-k*self.zelevation

    Fiddle around with the value of k till everything is just offscreen.

  • Thanks I'll try this.

  • To expound on the math idea here’s how to calculate the y to place the object just off the bottom of the screen. Untested but the math should be correct.

    Var s=0
    
    Start of layout
    — create sprite at 320,240
    — sprite: set zelevation to random(-150,0)
    — set s to 3dcamera.DefaultCameraZ/(sprite.zelevation-3dcamera.DefaultCameraZ)
    — sprite: set y to viewportHeight(0)/2/s+self.height/2+scrolly
  • this is my approach and it working nicely

    On function 'placeRandom' (copy picked)
    ----+ System: While
    ----+ bubble: Is on-screen
    -----> bubble: Set Y to Self.Y+1

    EDIT:

    to adjust x to fill screen

    On function 'placeRandom' (copy picked)
     | Local number xLeft‎ = 0
     | Local number xRight‎ = 0
    ----+ System: While
    ----+ bubble: Is on-screen
    -----> bubble: Set X to Self.X-1
    
    ----+ (no conditions)
    -----> bubble: Set X to Self.X+(Self.Width×1.5)
    -----> System: Set xLeft to bubble.X
    
    ----+ System: While
    ----+ bubble: Is on-screen
    -----> bubble: Set X to Self.X+1
    
    ----+ (no conditions)
    -----> bubble: Set X to Self.X - (Self.Width×2)
    -----> System: Set xRight to bubble.X
    -----> bubble: Set X to int(random(xLeft,xRight))
    
    ----+ System: While
    ----+ bubble: Is on-screen
    -----> bubble: Set Y to Self.Y+1
Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)