u/Distinct-Magazine586

help a girl out

I dont understand why the balls are not spawning wherever I am like when Im at the center of the cam the balls would spawn left and right but not on the center because that is where I am or when I extend my arms the balls stop spawning altogether. also how do I make the balls more responsive when bouncing off me?

here is the script
def __init__(self, posName):

marOp = op("margins")
radOp = op("radius")
scnOp = op("screen")

self.posOp = op(posName)

self.ratio = scnOp.chan("h")[0] / scnOp.chan("w")[0]

self.margins = [0,0,0,0]

self.margins[0] = marOp.par.const0value.eval()
self.margins[1] = marOp.par.const1value.eval()

# FIX: DO NOT distort mask space
self.margins[2] = marOp.par.const2value.eval()
self.margins[3] = marOp.par.const3value.eval()

self.radius = radOp.chan("Radius")[0]

# -------------------------
# SPAWN (NO BODY AVOIDANCE)
# -------------------------

self.pos = np.array([

random.uniform(self.margins[0], self.margins[1]),

# always above screen
random.uniform(
self.margins[3] + 0.3,
self.margins[3] + 1.2
)

])

# -------------------------
# VELOCITY
# -------------------------

self.vel = np.array([

random.uniform(-0.0005, 0.0005),
random.uniform(-0.01, -0.005)
])

self.drag = 0.995
self.cooldown = 0
self.spawnCooldown = 10

def update(self):

sizOp = op("size")
body = op("mask")

if body is None:
return

# -------------------------
# COOLDOWN
# -------------------------

if self.cooldown > 0:
self.cooldown -= 1

if self.spawnCooldown > 0:
self.spawnCooldown -= 1

# -------------------------
# UV MAP
# -------------------------

u = np.interp(
self.pos[0],
[self.margins[0], self.margins[1]],
[0, 1]
)

v = np.interp(
self.pos[1],
[self.margins[2], self.margins[3]],
[1, 0]
)

# -------------------------
# COLLISION FIX (NO AIR HIT)
# -------------------------

hit = False

# IMPORTANT: sample slightly BELOW ball
sampleY = v - 0.025
sampleY = max(0, min(1, sampleY))

for o in [-0.015, 0, 0.015]:

sampleU = max(0, min(1, u + o))

pix = body.sample(u=sampleU, v=sampleY)

brightness = pix[0] + pix[1] + pix[2]

if brightness > 2.85:
hit = True
break

# -------------------------
# BOUNCE (ONLY REAL CONTACT)
# -------------------------

if (
hit
and self.vel[1] < 0
and self.cooldown <= 0
):

self.vel[1] = random.uniform(0.008, 0.015)

self.vel[0] += random.uniform(-0.001, 0.001)

self.pos[1] += 0.004

self.cooldown = 2

# -------------------------
# GRAVITY
# -------------------------

self.vel[1] -= 0.00035

# -------------------------
# LIMITS
# -------------------------

self.vel[0] = max(-0.03, min(0.03, self.vel[0]))
self.vel[1] = max(-0.05, min(0.05, self.vel[1]))

self.vel *= self.drag

# -------------------------
# MOVE
# -------------------------

self.pos += self.vel

# -------------------------
# WALLS
# -------------------------

if self.pos[0] < self.margins[0] + self.radius:
self.pos[0] = self.margins[0] + self.radius
self.vel[0] *= -0.85

elif self.pos[0] > self.margins[1] - self.radius:
self.pos[0] = self.margins[1] - self.radius
self.vel[0] *= -0.85

# -------------------------
# RESPAWN (NO AVOIDANCE)
# -------------------------

if self.pos[1] < self.margins[2] - self.radius:

self.pos[0] = random.uniform(
self.margins[0],
self.margins[1]
)

self.pos[1] = random.uniform(
self.margins[3] + 0.3,
self.margins[3] + 1.2
)

self.vel[0] = random.uniform(-0.0005, 0.0005)
self.vel[1] = random.uniform(-0.01, -0.005)

self.cooldown = 0

# -------------------------
# OUTPUT
# -------------------------

self.posOp.par.const0value = self.pos[0]
self.posOp.par.const1value = self.pos[1]

sizOp.par.const0value = self.pos[0]
sizOp.par.const1value = self.pos[0]
sizOp.par.const2value = self.pos[1]
sizOp.par.const3value = self.pos[1]

return

here is the .toe file
https://drive.google.com/file/d/1NTCQerPvpWuEQzu5eEuUTIff9yLZMo8J/view?usp=sharing

reddit.com
u/Distinct-Magazine586 — 5 hours ago

I am still a beginner and I need your help!

link attached is the .toe file I have for my project

I want to create an optical flow interaction for multiple raining balls. however, it doesn't seem to work. it only works with a singular ball

for context, I want to create multiple raining balls, as it bounces off once touching your body through optical flow

drive.google.com
u/Distinct-Magazine586 — 4 days ago