so, I’m trying to make a small lil sim of particles zipping and bouncing around. I’ve an enclosed space, where the camera is at one end and particles (protons, neutrons, electrons) will bounce around and interact. but for this of course, I’ll need a fair number of these particles, preferably placed randomly, with random velocities in each direction.
the best way I can see to do this is have empties spawn them in randomly, just beyond the cameras view, and have them with their random velocities and directions, move into view. I’m hitting an issue however with giving them velocities once their added in. specifically, I’m getting an
“list indices must be integers, or slices, not tuple” error.
I’ve tried everything I can imagine to fix it, and been looking up the issue for a couple hours now with no luck. here is my code:
import bge
import mathutils
import random
scene = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()
own = cont.owner
#actuators --------------------------
Add_elec = cont.actuators['Add elec']
Add_neut = cont.actuators['Add neut']
Add_pro = cont.actuators['Add pro']
#empty ------------------------------
for ob in own.children:
if 'kid' in ob:
child = ob
#propertys --------------------------
Type = own['Sp Ty']
Time = own['Time Elapsed']
#do stuff ---------------------------
Time += 60
Vco = 3
Vch = random.randint(0,1)
Vx = 0
Vy = 0
Vz = 0
if Vch == 1: #chance to set x velocity or leave 0
Vx = random.randint(-5,5)
else: Vco += -1
Vch = random.randint(0,1)
if Vch == 1:
Vy = random.randint(-5,5)
else: Vco += -1
Vch = random.randint(0,1)
if Vch == 1:
Vz = random.randint(-5,5)
else:
Vco += -1
if Vco == 0: #if all velocities are 0, make one not 0
Vch = random.randint(1,3)
if Vch == 1:
Vx = random.randint(-5,5)
elif Vch == 2:
Vy = random.randint(-5,5)
else:
Vz = random.randint(-5,5)
print(Vx)
print(Vy)
print(Vz)
#based on output of random actuator, stored in property 'Type', determine what to spawn.
if Type == -1:
Add_elec.linearVelocity[Vx,Vy,Vz]
elif Type == 0:
Add_neut.linearVelocity[Vx,Vy,Vz]
else:
Add_pro.linearVelocity[Vx,Vy,Vz]
now
[
Add_elec.linearVelocity[Vx,Vy,Vz]
Add_neut.linearVelocity[Vx,Vy,Vz]
Add_neut.linearVelocity[Vx,Vy,Vz]
]
would seem to be the problem lines. but “Vx, Vy, and Vz” are each single digit INTEGERS between -5 and 5. (even when setting them all to 0, or 1, the same error occurs.)
linearVelocity
the initial linear velocity of added objects.
Type:
list [vx, vy, vz]