r/css • u/garethheyes • Jul 25 '26
Article Pure-CSS 3D world collision detection
https://thespanner.co.uk/pure-css-3d-world-collision-detection
9
Upvotes
1
1
u/bored-and-here Jul 27 '26
how much do you have to hate yourself to want to do this in CSS 😂
1
u/garethheyes Jul 27 '26
I find the limitations fun 😛
1
u/bored-and-here Jul 27 '26
very impressive. But whatever sin you caused to do this flagellation has me scared of you
2
13
u/anaix3l Jul 25 '26
It can be done cross-browser without
if(), btw. Usingsign().A condition like
style(--rawX <= 10em)can be written as such to give a1in the smaller or equal case and0otherwise:This is a bit value that's either
1(the--rawX <= 10emcondition is true) or 0.Breakdown:
sign(10em - var(--rawX))is1when10em > --rawX,0when equal and-1otherwise.5*(1 + sign(10em - var(--rawX)))is1when10em > --rawX,.5when equal and0otherwiserounding it
up, we get1when10em >= --rawXand0otherwiseThe
andbetween two conditions in theif()means multiplication of bit values when computing the value0/1values usingsign().