Set the Vector3 of modular, interchangable parts?

This question is fairly confusing but I hope I can clear stuff up.

I am essentially adding a function to my game where you can swap out parts of a computer for other parts, such as real life where you can change graphics cards, CPUs, hard drives, etc.

My one issue is that these parts will not be exactly the same size. If they were it would be easy to set the vector3 of these parts when two parts are swapped, as I could simply create a dummy part that has the desired position, and when I equip a new computer part, I would just set it to the position of the dummy part.

This does not work for my parts though, as they will all be different sizes.

I have used a dummy part for the case as all cases are the same size and go on the exact same spot on a desk. Now that I have this case here, how can I place different parts in the right spots when equipped, considering that they could be differing in size?

I believe I can help you if you explain a little better how you want these parts to fit in the computer case. It’s very vague what you describe, if you showed some pictures of the desired result, it would be much clearer for everyone I think :slight_smile: .

Sure thing!

I have not modeled a GPU yet, but I have modeled the case. The yellow brick in the case is approximately where I would want it to be. My initial thought was to do the dummy brick idea as I said earlier for the part, and use it’s vector 3 to set the positioning of the GPUs, but not all GPUs would be the shape of the yellow brick.

Some could be much larger like this.

Or smaller like this.

I hope this helps clear confusion a tad bit.

If there is truly no other way, I could create a dummy part for every possibly computer part, in every possible case (because the cases themselves will differ in size aswell.) but I just see that a horribly unoptimized solution, as there could be dozens of variants for every part, and I’d have to do that, for every computer case, but after my 2 years of script-writing experience I can’t really think of a better solution.

It sounds like you need to specify an attachment point offset. Or easier still, make the connection point an invisible part in the card, and make it the model’s primary part.

Seems like a good idea, but how would I get it to align along the back and far side of the computer case? Would I still have to create a dummy part to set the vector3 to?

What you should do is know the positions of the walls L and R from this sketch (View from the top):

Careful as this depends on the Axis rotations you are using and it might need to be inversed!

Let’s suppose your left wall part of the computer case is L and the right touching wall part(behind wall) is R:

No matter what GPU you have, you can properly position it at height givenHeight by doing:

local givenHeight = 2
newGPU.Position = + newGPU.Size.X/2, givenHeight, R.Position.Z + newGPU.Size.Z/2)

Please take note of how I arranged the X and Z axis, that’s how your computers should be positioned for the above to work. If they are oriented differently, you will need to change the signs accordingly.

I think combining your idea and @JarodOfOrbiter’s idea of a part on the corner of the part, along with finding the desired edges, might be the best idea?

The whole rotation thing shouldn’t matter as all computers will be facing the same way.

Not going to lie, this actually looks like a fun scripting challenge, I’ll have a go!

The way I would do this is I would place some sort of attachment or invisible part in the corner of the component’s intended location. This will be the corner that will essentially be the component’s AnchorPoint (Like with UI elements).

Place this invisible part with the negative Z axis (the front) facing the front of the computer, and with the Positive X axis (the right) facing the closest side of the computer, as shown below:


Almost there…
Make sure that the components have bounding boxes that align with the invisible part.

Now, all you need to do is get the size of the CPU. Half the size, and then multiply the invisible part’s CFrame by CPUhalfSize

and now you’ll have the position that you need to place the CPU at.

I think this sums it up. All 3 responses can be combined for probably the easiest solution.

Each case will have a part for where the GPU, CPU, ram, etc. needs to go. It won’t be much of an issue now though, as you don’t have to make a separate part for every type of CPU or GPU, as instead of setting the entire group’s CFrame to the part, you put a part in the corner of the GPU that you set to the CFrame of the part in the corner of the computer case.

This way, the GPU can be set no matter the orientation of the PC, and you don’t have to worry about differing sizes of GPUs, because the only position that matters is the position of a part in the corner of the card, that will remain constant in size.

Thank you to all who helped! This seems like a pretty obvious solution and I am surprised that I didn’t consider it sooner but you guys helped a bunch to figure it out!

1 Like