• Technical question about building-snapping system Rust
    18 replies, posted
Hi everybody, how Rust building-snapping system works? Is it based on a grid system or something like that? How the raycast recognizes the near foundation? Thanks ahead!
Not specific enough to be answered accurately. Please rephrase.
[QUOTE=N4;48169880]Not specific enough to be answered accurately. Please rephrase.[/QUOTE] also possibly clarify [B]why[/B] you want to know so we can answer in context.
It's just for curiosity, i'm and indie game developer.. i just test my own building system, i'm curious.. they use triggers or 'anchor points'? [IMG]http://puu.sh/iWlMc/262238b1af.jpg[/IMG] For now i'm using triggers, but i was curious of knowing the system of Rust, i think that triggers can be too expensive in performance. Thanks
Hello, I cant tell you the exact system rust uses but i do know from coding the Rust Building Planner i doubt they are using a grid system, as the triangles together with square foundations in the amount of ways these can connect would be extremely hard to do perfectly in a grid - What we ended up doing in the building planner was to create a "Snap Point" system, Each block got some defined snap points that we could search for when snapping pieces together (Mostly each corner) Eg an foundation pice have 4 snap points, one in each corner. Then you are placing a wall, that also got 4 snap points, one in each corner We would just search for the two closest snap points from each block, if there is two we snap. This is atleast how we did it to get as close to the in game system as we could in an reasonable way. I am not saying this is how rust does it, but it is a solid system and i would think rust bases of something like it.
Not super detailed but garry talks about it in his blog post here [url]http://garry.tv/2015/06/14/unity-tips/[/url]
that a military secret. u wont know it ever
[QUOTE=kentbakk;48195246]Hello, I cant tell you the exact system rust uses but i do know from coding the Rust Building Planner i doubt they are using a grid system, as the triangles together with square foundations in the amount of ways these can connect would be extremely hard to do perfectly in a grid - What we ended up doing in the building planner was to create a "Snap Point" system, Each block got some defined snap points that we could search for when snapping pieces together (Mostly each corner) Eg an foundation pice have 4 snap points, one in each corner. Then you are placing a wall, that also got 4 snap points, one in each corner We would just search for the two closest snap points from each block, if there is two we snap. This is atleast how we did it to get as close to the in game system as we could in an reasonable way. I am not saying this is how rust does it, but it is a solid system and i would think rust bases of something like it.[/QUOTE] I really thank you for the hints! I'm also curious about the 'detecting system' for finding the point in order to get the two snapped closest points, for example a wall, if i fire a raycast on front of my camera and on front of a future wall, the raycast hits nothing and i'm not able to loop for a snap point. Thanks again!
Now i should mention we both work on different platform - I am mostly using html5 for the planner as it is a 2d site. I have no clue how you would go about replicating the system in Unity. But i am happy to help you with the system functionality in terms of explaining the system we use a bit closer if you want me to :) Im sorry i cant help you on the exact code in unity tough! (For our system we solved detecting by strapping each snap point with an actual invisible object that is "pinned" to the objects snap point so essentially we have 4 objects pinned to the main building part to make it a bit easier to loop all the snap point positions and store them in an array where we later loop the array and calculates distance between them - selecting the smallest value unless that is over X size) As i said i can probably explain this better and in more detail if you want me to!
[QUOTE=kentbakk;48197896]Now i should mention we both work on different platform - I am mostly using html5 for the planner as it is a 2d site. I have no clue how you would go about replicating the system in Unity. But i am happy to help you with the system functionality in terms of explaining the system we use a bit closer if you want me to :) Im sorry i cant help you on the exact code in unity tough! (For our system we solved detecting by strapping each snap point with an actual invisible object that is "pinned" to the objects snap point so essentially we have 4 objects pinned to the main building part to make it a bit easier to loop all the snap point positions and store them in an array where we later loop the array and calculates distance between them - selecting the smallest value unless that is over X size) As i said i can probably explain this better and in more detail if you want me to![/QUOTE] If you can explain me this better it would be great! Thanks!
Okay, Lets take an example there is already placed a Foundation on the ground The user is trying to place another square foundation next to this one - obviously he wants this to snap So now we find the closest object the user is looking at as this is probably what the user wants to snap the object to. Now we know what object and the location of the object the user wants to snap the new object to. So now we can start to actually snap the object (In my pictures the green dots are on the already placed foundation and the yellow ones are the new object the user wants to place) The first thing we do is to get all the snap points from the already placed object: [IMG]http://i.gyazo.com/a872cd0a5752c7604724f5bed4d17349.png[/IMG] You should store the location of each snap point (Green dots on the image) There are many ways to do this - One is to use math to calculate the offset from the middle of the object or if your engine supports it mark of said position with a "image point" or something in that order Bottom line is you need to get the cordinates/position of each possible snap point Then we must do the same for the object the user wants to place: [IMG]http://i.gyazo.com/89885a62443a89fd30240f9c7b85ba4e.png[/IMG] Now you should have two arrays one with all the snap positions of the already placed objects And one with all the snap points for the object the user wants to place. Now it is a matter of doing fancy math, varies for 3d and 2d environments Due to the third dimension. so the exact distance equation you will have to lookup for your needs. For simplicity i will call the array containing the already placed objects snap points for GreenArray and the other for YellowArray So now you will have to calculate the distance from each point to all the other points on the other object Eg you start with Green1 (Top Right snap point) And calculate the distance from Green1 to Yellow1, Yellow2, Yellow3 and yellow4 This must be done for all the green points In the end you will have a ton of distance numbers (That you should also log what distance is for what pair of snap points) eg. store in an array with the key being the pair name (Green1-Yellow2) Now you can actually do the snapping, In your array of distances you must select the one with the smallest distance. You can also add a check to see if the distance is over so and so much so the system wont snap an object on the other side of the map. red boxes in the picture is the smallest distance points: [IMG]http://i.gyazo.com/61fd6ae92b641a7916c8b547c6239aa2.png[/IMG] Now that you know the smallest distance you must lookup what pair that gave you the smallest distance Then it is just a matter of setting the position of the object the user wants to place (yellow) to the greensnap point that gave the smallest distance and offset to center it (or if you can move the snap point and have the object follow you could just match the points) (Purple is the two red ones moved ontop of eachother) [IMG]http://i.gyazo.com/f25e46c9f9b0c3d8d2fdd7638af54b05.png[/IMG] In the example you would get two "smallest" distances to cover cases like that you can make additional checks or simply ignore the duplicates. In the end you should have two foundations next to eachother! Im sorry for my crappy explanation its quite an extensive system and it is hard to type it out! Tried to make it a bit easier to follow along by adding some pictures :) You will have to adapt parts of this to cover the third axis in 3D but nothing to mayor!
[QUOTE=kentbakk;48198210]Okay, Lets take an example there is already placed a Foundation on the ground The user is trying to place another square foundation next to this one - obviously he wants this to snap So now we find the closest object the user is looking at as this is probably what the user wants to snap the object to. Now we know what object and the location of the object the user wants to snap the new object to. So now we can start to actually snap the object (In my pictures the green dots are on the already placed foundation and the yellow ones are the new object the user wants to place) The first thing we do is to get all the snap points from the already placed object: [IMG]http://i.gyazo.com/a872cd0a5752c7604724f5bed4d17349.png[/IMG] You should store the location of each snap point (Green dots on the image) There are many ways to do this - One is to use math to calculate the offset from the middle of the object or if your engine supports it mark of said position with a "image point" or something in that order Bottom line is you need to get the cordinates/position of each possible snap point Then we must do the same for the object the user wants to place: [IMG]http://i.gyazo.com/89885a62443a89fd30240f9c7b85ba4e.png[/IMG] Now you should have two arrays one with all the snap positions of the already placed objects And one with all the snap points for the object the user wants to place. Now it is a matter of doing fancy math, varies for 3d and 2d environments Due to the third dimension. so the exact distance equation you will have to lookup for your needs. For simplicity i will call the array containing the already placed objects snap points for GreenArray and the other for YellowArray So now you will have to calculate the distance from each point to all the other points on the other object Eg you start with Green1 (Top Right snap point) And calculate the distance from Green1 to Yellow1, Yellow2, Yellow3 and yellow4 This must be done for all the green points In the end you will have a ton of distance numbers (That you should also log what distance is for what pair of snap points) eg. store in an array with the key being the pair name (Green1-Yellow2) Now you can actually do the snapping, In your array of distances you must select the one with the smallest distance. You can also add a check to see if the distance is over so and so much so the system wont snap an object on the other side of the map. red boxes in the picture is the smallest distance points: [IMG]http://i.gyazo.com/61fd6ae92b641a7916c8b547c6239aa2.png[/IMG] Now that you know the smallest distance you must lookup what pair that gave you the smallest distance Then it is just a matter of setting the position of the object the user wants to place (yellow) to the greensnap point that gave the smallest distance and offset to center it (or if you can move the snap point and have the object follow you could just match the points) (Purple is the two red ones moved ontop of eachother) [IMG]http://i.gyazo.com/f25e46c9f9b0c3d8d2fdd7638af54b05.png[/IMG] In the example you would get two "smallest" distances to cover cases like that you can make additional checks or simply ignore the duplicates. In the end you should have two foundations next to eachother! Im sorry for my crappy explanation its quite an extensive system and it is hard to type it out! Tried to make it a bit easier to follow along by adding some pictures :) You will have to adapt parts of this to cover the third axis in 3D but nothing to mayor![/QUOTE] Thanks, it's a really clear explanation. My real problem is to found the best way to detect basically 'what and where the user wants'. In detail, consider my actual system: [IMG]http://puu.sh/iYd5X/1ea162556b.jpg[/IMG] With 'trigger zones' i know that if my raycast hits the trigger, i will snap and place there my object. It's not good for obvious reasons (performance), with your system we have only 'snap points', it can works perfectly but: consider again the screen above, how can i know that i just look at 'bottom of foundation X' without cycling all foundation placed? I wanted to find a 'detecting system' that provides me the closest object to snap and with a raycast in the center of my camera i check the distance between 'anchor points' and hit point. But i'm still confusing of how to obtain, even between adjacent foundations, the correct building the user wants to snap to. I thank you again for your awesome hints! It's not your field then you probably can not give me a detailed explanation on the detecting system but thanks the same!
[QUOTE=Ruggeri96;48198841]Thanks, it's a really clear explanation. My real problem is the find the best way to detect basically 'what and where the user wants'. In detail, consider my actual system: [IMG]http://puu.sh/iYd5X/1ea162556b.jpg[/IMG] With 'trigger zones' i know that if my raycast hits the trigger, there i will snap and place my object. It's not good for obvious reasons (performance), with your system we have only 'snap points', it can works perfectly but: consider again the screen above, how can i know that i just look at 'bottom of foundation X' without cycling all foundation placed? I wanter to find a 'detecting system' that provides me the closest object to snap and with a raycast in the center of my camera i check the distance between 'anchor points' and hit point. But i'm still confusing of how to obtain, even between adjacent foundations, the correct building the user wants to snap to. I thank you again for your awesome hints! It's not your field then you probably can not give me a detailed explanation on the detecting system but thanks the same![/QUOTE] Its not my highest field that is for sure, but i can sure throw out some ideas! The real issue with a detection system is the fact its engine specific and will depend on what your engine got readily available for you and what you have to make for yourself. The basic thing would be to loop all building parts in X distance from the building part the user wants to place (Or the users position?) and select the one with the smallest distance from what the user is trying to place.
[QUOTE=kentbakk;48198922]Its not my highest field that is for sure, but i can sure throw out some ideas! The real issue with a detection system is the fact its engine specific and will depend on what your engine got readily available for you and what you have to make for yourself. The basic thing would be to loop all building parts in X distance from the building part the user wants to place (Or the users position?) and select the one with the smallest distance from what the user is trying to place.[/QUOTE] This is the real issue, i can't cycle all buildings (this will be more expensive than physics check).. i can make a list of 'current building parts visible by the camera', i'm not sure if this can be a valid solution, but consider this situation (that is very valid for all buildings, pillar, walls, doorway, ceil etc.): [IMG]http://puu.sh/iYfz9/599960d3ad.jpg[/IMG] [IMG]http://puu.sh/iYfNG/312909d902.jpg[/IMG] As you see, in this case i look at 'air' (where should be the pillar to place), my raycast hits the trigger (which occupies the part that I should look virtually for placing the pillar). Now consider the same situation [B]without trigger[/B] but only snap points and a raycast to know where i'm watching: [IMG]http://puu.sh/iYgdg/0ce83a37e0.jpg[/IMG] As you see in this case, without direct physic checks, i know these things: End Point of the raycast (if he no hits anything); Hit point of the raycast (if he hits something); Let's say that i pick the End point of the ray, it's a world point and i need to loop through a building list in order to find the nearest (performance cost, not good); now i should cycle all the 'snap points' to find the shortest distance.. Result? Wrong result, i will snap in the wrong place: As you see the system doesn't work in this way, I think there should be some element of contour or some concocted system that allow me to detect the correct point and snap point, also if i look virtually at 'air'.. Thanks for your help![IMG]http://puu.sh/iYgLT/45fe9cf569.jpg[/IMG]
Yeah its a lot up to how you want to handle it, for looping limiting it to only in X distance near you should save your performance, Playing around with it is the only true way to get somewhere! Due to my limited knowledge in unity i can't really help you much with that but feel free to ask me anything related to the system and i will try to answer it as good as i can! But i do believe ultimately it's a matter of playing around with the info i gave you and somehow adapt it to function in an engine like unity :)
[QUOTE=kentbakk;48199249]Yeah its a lot up to how you want to handle it, for looping limiting it to only in X distance near you should save your performance, Playing around with it is the only true way to get somewhere! Due to my limited knowledge in unity i can't really help you much with that but feel free to ask me anything related to the system and i will try to answer it as good as i can! But i do believe ultimately it's a matter of playing around with the info i gave you and somehow adapt it to function in an engine like unity :)[/QUOTE] That's it! i will try some detecting system (trigger reticular) to know what is in my field of view and then check the nearest snap points. I have to think about the fact that: In order to place a Ceil i have to detect the wall/pillar near the point that the player is looking, for placing a pillar i have to detect the foundation near the point that the player is looking, for snap foundation i have to detect the foundation near the point that the player is looking and so on.. I will try with trigger reticular to simulate a 'field of view' and i will update you, thanks for all man. :dance:
Wrong forum... [url]http://facepunch.com/showthread.php?t=1459923[/url] [QUOTE=ryankingstone;47487256]Unity3D discussion - go![/QUOTE]
Haven't played with Unity much but here's a couple ideas that came to mind reading all this: 1. Use a SphereCast on the player/camera to determine what building blocks (or snap points) you need to loop through. There shouldn't be more than 10-15 tops within the range of placement so it shouldn't be a significant hit on performance 2. I don't know the unity or even 3d terms for this, but to choose between a near and far snap point, just look at how high your ray is. If both snap points are at the same distance from the ray itself like in your image, looking slightly up/down should change the distance.. The higher the player looks, the further he wants to snap and the lower he looks the closer he wants to snap.
[QUOTE='Deicide[RS];48200904']Haven't played with Unity much but here's a couple ideas that came to mind reading all this: 1. Use a SphereCast on the player/camera to determine what building blocks (or snap points) you need to loop through. There shouldn't be more than 10-15 tops within the range of placement so it shouldn't be a significant hit on performance 2. I don't know the unity or even 3d terms for this, but to choose between a near and far snap point, just look at how high your ray is. If both snap points are at the same distance from the ray itself like in your image, looking slightly up/down should change the distance.. The higher the player looks, the further he wants to snap and the lower he looks the closer he wants to snap.[/QUOTE] Thanks for the hints, i'm trying different detecting system to know which is the best, then i will profile all and finally i will optimize the system. I will update you, thanks :)
Sorry, you need to Log In to post a reply to this thread.