Announcement

Collapse
No announcement yet.

Building snapping system (collision based concept)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    Seems the pictures are gone now.. Might check on it later

    Leave a comment:


  • started a topic Building snapping system (collision based concept)

    Building snapping system (collision based concept)

    So, inspired by this YouTube video I made a collision based building snapping system in blueprint.

    Click image for larger version  Name:	snapping.png Views:	0 Size:	567.6 KB ID:	1692575
    ​Building parts placed ingame using snapping (Red - Foundations | Blue - Roofs | Green - Walls | Yellow - Slopes)

    The ingame handling is pretty smooth and the results are looking good so far.

    Click image for larger version  Name:	snapping2.png Views:	0 Size:	327.0 KB ID:	1692576
    Editor view of one building part (components based on box colliders used for custom traces and snap configuration)

    As you can see the configuration of these can become quite messy. All in all they are fairly easy to use though. Every box has an Enum category set that only allows one building type to be snapped there. The box's world location and rotation is used for the basic snapping calculations. There are Booleans you can switch to limit the different rotations an object can have after snapping (like walls on a foundation can only be forward or backward to the snap box). As the boxes have their pivot point in the center, a local offset was needed so the snapping works correctly.

    The box's extent can be tweaked in order to control where the player has to look in order to trigger snapping. Boxes get traced by multi line traces from the camera (and as I made this for a top down view, through the HitResultUnderCursor and a bit further in that direction). I used a custom collision trace channel for them.
    Click image for larger version  Name:	snapping4.png Views:	0 Size:	294.5 KB ID:	1692577
    Show Rotation and Snap Offset

    Click image for larger version  Name:	snapping5.png Views:	0 Size:	15.8 KB ID:	1692578
    Box configuration

    Click image for larger version  Name:	snapping3.png Views:	0 Size:	23.6 KB ID:	1692579
    Hierarchy of a foundation snapping configuration

    There are quite a few collision boxes for each actor so I don't really know about the performance hit. With 512 foundations placed, I dropped to about 18 fps in the editor and was at solid 40 fps in the game (depends on the setup of course).

    Maybe this could be improved with having less colliders or even only having colliders on the object that has to be placed. The advantage when having it this way is that you can aim somewhere in the air and still hit a collider to trigger snapping. If you don't have them you'd rely on the player aiming directly at the building he wants to snap to and also have to calculate which snap point he prefers, probably based on lowest distance of the trace hit to all the possible snap points.

    I tried something similar before with a sphere trace from the cursor hit location that scanned for building parts, took the closest snap point of wanted category and snapped to that. This was not collision based, the snap point was a child class of Arrow components actually. It worked, but the snapping was kinda jerky as the player had to aim at least somewhere near the target block in order to trigger snapping, and it would always default to the closest point. This was sometimes not desirable eg. when you have roofs away from the ground and your hit locations are basically limited to aiming directly at it. Like when trying to switch between placing a wall on top or below said roof.

    Other techniques use socket points for the snapping, but I also wanted something more intuitively controllable from within the blueprint.


    Conclusion:
    The system as it is works pretty well and I might even make it public so people can use it (there are not many good tutorials on this and I don't think people should have to pay for something as simple as this).

    As you can see however, it is not yet perfect, so I welcome any suggestion, advice, opinions or maybe this is even complete bull***t and you can tell me how things like this are actually done

    If there is demand and I got the time, I'll upload the project on github and link you there.

    Thanks and cheers!
    Last edited by LordStuff; 11-29-2019, 03:17 PM.
Working...
X