Im working on a few personal projects, one of which involves figuring out how to make a system where the player can create their own vehicle from a range of pre-made pieces (Kind of like the gummi ship editor in Kingdom Hearts 2).
I know each piece will need to be created separately, and be able to fit with each other pretty well, and I know I’ll be using raycasting to determine when the player is clicking on an existing block/piece in the builder.
I dont want a full code or anything, just a nudge in the right direction in order to learn the coding required to script something like this.
I would build the pieces as a sort of prefabs where I place “connection nulls” where you can attach other objects. If you have different types of objects too, like different wheels, spoilers, weapons etc. just make more types of connection nulls.
You could use naming as a way to determine them, because you can easily travle/parse down a Gameobjects children.
So like this:
prefab: CAR-TYPE-A
Connections: WHEELS (x4) or perhaps two sets (FRONT/BACK), SPOILER, TRAILER etc.
On the “addable pieces” you make a similar approach (a connection area) perhaps you could use a radius/sphere collider to determine if its over the connection point of the parent.
Or you could let the click on the connection type show the list of possible objects that can be attached here.
Each attachable object could again be Prefabs, so you have script-logic and components configured once they are spawned/added to the object.
This could be an easy way of having physics correctly configured for different sets of tires and heavy bodies on vehicles/shields etc.