With a little bit of scripting and some building, I’m pretty sure this can come true. (Although I’m unsure Roblox Studios supports this YET)
If I were you, I would try scripting a block that, when touched by the saber, would be replaced by two blocks half the size of the original block, which would simulate the block being cut in half.
I’m not very good at scripting and building though, so whatever I just said is just an idea on how to do it.
I’d recommend doing the exact opposite. Imagine having many breakable blocks, and one script per block… that would cause lag, and a bunch of unwanted / avoidable memory issues. Instead, every frame perform a raycast either from the tip of the lightsaber to the bottom of the saber, or from the bottom of the lightsaber to the top. Then if the raycast hits the brick, you could of course cut the brick in half. The only hard part would be getting the brick to actually split in two. Obviously you could duplicate the brick, and make both bricks half their original size, but that sadly that would get unrealistic real fast… Imagine a player cutting a triangle out of 1 brick. It would be really hard to make the brick cut in half properly, and get which section of the brick you cut off.
You can store an already “cut block template”. Call it when necessary such as a saber/part touching the cube, once it does, clone the template, change it to fit the needs slightly such as orienting it randomly (Or just having multiple random templates though I don’t know how efficient that’ll be) then summoning it relative to the position as such. If you want to show the splitting effect, you can animate it and then play the animation on the template or tween it
Method 1: If you’re only using straight line, and aren’t doing anything fancy with the parts simply calculating wedge sizes might do? Saber “draws” line on block, spawn two wedges to fit block’s old position and also follow that linear path?
Or a combo of wedges and parts (along with some welds) to fit with the line the lightsaber “drew”
Method 2: Requires a little more processing, but having a big part that consists of many smaller parts, as the light saber touches those parts they are despawned/destroyed with fancy melting effects.
Might by laggy though with all the small parts, and would require some annoying building practices…
Of course, fancy optimization could be used to limit the amount of parts in the vicinity and also render them as singular parts for the client
CAUTION: Math and Trigonometric Manipulation content up ahead, turn back now before it’s too late.
Have no fear, for I think I have found what you’ve been looking for:
EgoMoose had a challenge on ScriptingHelpers that allowed people to find methods and ways to accomplish what he did in those gifs, Snack Break Problem #28 - Scripting Helpers
Luckily for us he provided the solution/source code, so you can take a look at it and see how you can implement it with your Lightsaber code.
From what I’ve read, many have overlooked realtime CSG. In theory, it’d be easy to just create your saber mechanics using Roblox’s in-built functionality.
Was surprised nobody mentioned this earlier. The best way to implement this is to start with the real time CSG and use EgoMoose’s solution as a backup as CSG often fails with a large number of manipulations.
In case an operation fails, you can check and destroy if the part is very small, or just ignore if it is a union.
First of all we can add our part as a variable. After that you can take all the other parts that can union with the part.
local part = workspace.Part1
local otherParts = {workspace.Part2, workspace.Part3, workspace.Part4}
And finally we can make our Union Operation.
local newUnion = part:UnionAsync(otherParts)
Basic Demonstration With In-Game Modeling
First we will do the first step with unions. and then we will subtract our part instead of unioning it.
local part = workspace.Part1 --//Our main part.
local otherParts = {workspace.Part2, workspace.Part3, workspace.Part4} --//Other parts
local newUnion = part:SubtractAsync(otherParts) --//Negating the part
What I explained here is the same as the one in the wiki page. Roblox made a open sourced example with this api in this game. If you want you can take a look at it here: Rotating Windows - Roblox
Thanks for replying Syharaa. This fits great, I will just have to make it run more than once. After looking over the code, I have to say you were right, it is complex. I don’t know how it is performance wise, but since it works, I will mark you as a solution.
@ElliottLMz@nooneisback@skwoginc
After playing the game provided by skwoginc, I realized that real-time CSG provided by Roblox might not be such a bad idea. I know “Who ate my spaghet” uses it after reading the replies to the provided Reddit post. Although, I did see that it does not work well with spheres, I can work around this as i did say I am only looking to manipulate block parts in my original post. Thank you for replying!
The issue with speheres is that they have a high triangle count, quickly making the operation too complicated. It is better to make some kind of a custom “spheroid” by combining 3 normal parts, 8 wedges and 8 corners.