How do I convert BoundingBox values of a billboard sprite on a 3D layer to a 2D layer?

Not favoritedFavorited Favorited 0 favourites
  • 4 posts
From the Asset Store
Template for a basketball game with a 3D aspect (illusion of 3D)
  • Context: Ultimately what I am trying to do is check to see if objects on a 3D layer overlap with objects on a 2D layer.

    I have sprites utilizing the new billboard feature in a 3D Layer (Red Circles).

    When I want to check if they overlap objects on a 2D layer, I spawn collision checking objects at the correct locations using 3DCamera.LayerToLayerX/Y. These are the green circles above, it works perfect!

    The problem is then in getting them to properly resize to cover the same space the objects on the 3D layer do. I originally tried to convert their BBoxRight-BBoxLeft/BBoxBottom-BBoxTop values for the size, but this didn't work:

    Which kind of makes sense to me, but now I am not sure how I should be approaching this. How can I determine the size of the 3D objects when converted for the 2D layer?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Doesn't BBox calculate in X/Y only? I am assuming in your case the vertical axis is Z?

    If your objects are square/circular, I would just get the center in screen coordinates (using LayerToCanvas) and calculate the width/height using the distance of the billboard to the camera plane (as we know at that distance, the Width/Height are exactly 1:1 with the width//height on screen).

  • Alright, I figured this out! Funky Koval I wasn't sure how to even approach the suggestion you put forth (thank you all the same) and I was concerned that it wouldn't easily allow for things like Z axis rotation being reflected on the collision checking sprites.

    Ultimately what I did was add 4 image points to the Billboard Sprites on the 3D layer that correspond to their top, bottom, left, and right sides (effectively recreating bounding boxes)

    Then after spawning the collision checking sprites on their 2D layer at the 3DCamera.LayerToLayer positions, I set their size using the distance from the image points on the 3D layer:

    Finally, if you want to set the angle of the 2D collision checker to the billboard sprites Offset Z, you do so with those same imagepoints:

    Ultimately I am going to try using this to create a pseudo-3D collision checking system for attacks/enemies. Attacks will first need to collide on the 3D layer, then the game will run this separate check to see if they collide on screen.

    This approach works in this dungeon crawler view where the camera is going to be pretty static during combat, I don't know how well it would work elsewhere.

  • Yes, the 4-point approach would be what I would use if the shapes were not square or billboards. This is absolutely valid and (as you've noticed) accounts for rotation and even mesh distortion. Glad to see you've figured it out!

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)