Cubyz icon indicating copy to clipboard operation
Cubyz copied to clipboard

Make particles actually workable

Open RanPix opened this issue 2 months ago • 10 comments

WIP, adds a way to nicely create spawn behaviors for particles and define their spawn data (at the moment collisions in the game are broken so particle collisions are also kind of messed up, also includes changes from currently open particle prs)

example command: /particles cubyz:poof ~ ~ ~ false 200 .{ .type = .sphere, .radius = 10, .mode = .direction, .direction = .{0, 1, 0} , .coneRadius = 0.5} at the end you see a zon spawn configuration where you can define a spawn shape to use (point, sphere, cube) and their corresponding data, for example a sphere needs a radius whereas a cube needs a size which takes a vector3, also you can see you can use a mode which sets the fly direction of the particle (spread, scatter, direction) direction is the only one which needs to be defined with a value so if you want something else you would do this: /particles cubyz:poof ~ ~ ~ false 500 .{ .type = .cube, .size = .{10, 10, 0}, .mode = .scatter}. Another example: /particles cubyz:poof ~ ~ ~ false 10 .{ .type = .point, .mode = .spread} the difference between spread and scatter is that spread will make the particle go in a direction from its center, and scatter goes randomly. You can also set spawn properties such as drag, density, velocity, rotationVel, lifeTime (all of those take .{0, 0} vector 2 values and the first element means minimum and second maximum), randormRotate (which takes true or false), .color = .{0xff00ff, 0x00ff00} and .colorRandom = .channel (only one option here for now, idk how else i could make it). example: /particles cubyz:flamew ~ ~ ~ false 750 .{ .type = .sphere, .radius = 0.25, .mode = .spread, .density = .{ -0.5, -3 }, .velocity = .{20, 30}, .drag = .{10, 15}, .color = .{0xff00ff, 0x00ff00}, .colorRandom = .channel}

examples for spawning using code are in physics.zig line 240, and renderer.zig line 1115

RanPix avatar Oct 19 '25 20:10 RanPix

you can also now set spawn properties such as drag, density, velocity, rotationVel, lifeTime (all of those take .{0, 0} vector 2 values and the first element means minimum and second maximum) and randormRotate (which takes true or false)

RanPix avatar Oct 20 '25 08:10 RanPix

i think this is ready for a review, i left some example code for using this new api in physics.zig and renderer.zig. this should also be a good time to finalize the data that particle (and its type) should contain and where

RanPix avatar Oct 21 '25 17:10 RanPix

rebased

RanPix avatar Oct 30 '25 13:10 RanPix

drag has no use now so im removing it

RanPix avatar Nov 06 '25 15:11 RanPix

all changes have been made

RanPix avatar Nov 06 '25 15:11 RanPix

should i add terminal velocity or some sort of slowing forse to particles? so that its possible to create nice explosion clouds, particles could spread out quickly and stop quickly making a nice cloud

RanPix avatar Nov 07 '25 19:11 RanPix

should i add terminal velocity or some sort of slowing forse to particles?

I think a factor that scales the actual friction coefficient would make sense (called drag coefficient in physics)

IntegratedQuantum avatar Nov 07 '25 19:11 IntegratedQuantum

please update to the new Zig version

IntegratedQuantum avatar Nov 24 '25 16:11 IntegratedQuantum

done

RanPix avatar Nov 25 '25 14:11 RanPix

done

RanPix avatar Nov 26 '25 20:11 RanPix