Hello! I am attempting to facilitate player to part placement and interaction in my game. I seek the best possible and safe methods.
What do you want to achieve? Keep it simple and clear!
I would like to create a system where players can place and build a flat blob out of parts of different shapes. Cylinders, triangular prisms, rectangular prisms, etc. There are a few limitations however:
Parts must touch other placed parts.
The player should be able to delete, “trash” parts.
What is the issue?
I do not know how to go about creating a good system that follows the above limitations. The most central piece is that the part must “snap” to the nearest part if it isn’t touching one where it is placed.
What solutions have you tried so far?
I have browsed the devforum for solutions. Most notable of which are egomoose’s furnitures placement tutorial and tunicus’ API for placement. However, I seek guidance and building or adapting my own system to meet the needs outlined above.
To summarize: I would like to know some of the best practices with player to part interaction that is secure. I’m open to several ideas, anything from almost all ui to primarily based on the mouse or touch.
Please note: I’d prefer ideas to be mobile compatible too.
Thanks everyone, the devforum has been an invaluable resource as I move forward!
Just giving you what comes to mind here; apologies for any oddities or confusion in language, I’m very sick today.
You could use some elements of egomoose’s furniture placement system, but adapt placement such that on each mouse movement, click or tap (mobile support yay!), it automatically snaps the part or object you’re placing to touch the nearest object to it.
You could pretty simply set the orientation of this new object to to be the same as the old one, and then it’s just simple CFrame or Vector math to get the parts to be touching and not overlap using the size of each part. If you want to allow the players to be able to rotate, you can do that as well but just run the same math check above based on the new orientation and position.
As far as deleting parts, you have a few ways to do this but you could set it up in a way very similar to Nodes in Java if you’re familiar there, otherwise a loop to check if parts are touching would be more performant. If you’re going the loop way, I’d recommend some way to index parts so you don’t accidentally delete every part by deleting a part in the middle of a chain the player has placed down.
As for best practices on player to part interaction, personally I prefer putting the player in a top-down view over their build area. It makes it easier to select parts, and you can bind the y-level at which they are placing the object to the “floor” or “level” they are placing an object on. This also allows objects to be stacked if two are placed in the same area.
Hope this helps.
Thank you very much! As it happens, players in my game are already in top-down. I do have one additional question for you:
As players will be allowed to place at varying points in time, how would I make this system “scale” to match the number of players who are currently placing parts? Obviously, it would be a serious problem If there are players placing on top of each other.
You have been very helpful!
Realistically that’ll come down to your server sided validation to ensure they aren’t placing parts on top of each other. ie: request from Player1 to place a part at x position, Player2 sends one a fraction of a second later to be at x position as well. Only Player1’s is respected as they placed theirs first. Your simple check here is just going to be verifying on the server that parts placed by different players are not intersecting or placed in the same location. If they are, deny the later request and let the client know it can’t place there.
Actually, I mean that the players cannot see what the other players are placing. Each player gets their own “zone” of sorts. I seek advice on how to efficiently do this. I will definitely be implementing the methods you described for double-checking placement as a backup. Thanks!
Edit: Each player doesn’t need their own zone, but their must be no conflicting zones as players enter and leave the placement menu. This is what I mean by “scaling”.