Lightning using object that emits children branches


Awesome! Is it possible to make it in Blender render?

wow good job!


I was going to clean it up a bit - but here is the raw - rapid prototype

it uses a added object from a hidden layer, that only adds copies of it’self if it’s the original, and they move to the target randomly, but the ‘original’ cube moves to the target much more directly, when it strikes, it draws the path it, and it’s children took, if a ‘secondary’ object hits, it draws it’s path and all it’s (sibling?) paths.


BranchingLightning.blend (468 KB)

Interesting. I used a recursive random point algorithm but it didn’t save much logic compared to this. I’ll take a look at it later…

Looks very nice.
Don’t know much about BGE, but is it possible to generate geometry with it?

yeah, I store the path each frame using own.worldPosition.copy() and I draw the path using bge.render.drawline

one could do something similar with particles,

particles move randomly but weighted to target,

Ooooh! I tried the same approach once, but yours looks much better! I’mma take a glance at that coding magic! xD

Edit: Hah that’s really cool : D Very easy to understand once “Show Physics Visualization” is enabled. Hmmm, maybe I should try to see how close I can get to your look using only code.

I think you should avoid code like this though:

own.worldPosition+= own.worldOrientation.inverted()*Vector([(x*-.25)+ (bge.logic.getRandomFloat()*(x*.5)),(.125)+(bge.logic.getRandomFloat()*(.25)),(x*-.25)+(bge.logic.getRandomFloat()*(.5*x))])

at least break it down in to:

x= ...
y= ...
z= ...

own.worldPosition = own.worldOrientation.inverted()*Vector((x,y,z))

Part of the python style guidelines suggest that lines shouldn’t be longer than a certain length. If you have to turn on line wrapping then it’s safe to say that your lines are too long. It makes it difficult to read.

Imagine you’re writing a cake recipe, you don’t want the whole recipe in once sentence. You also want a reader to know what the ingredients are. Consider:

eggs = 2
flour = 500
water = 0.5
sugar = 12
butter = 2

cake = (eggs+flour+water)*(sugar+butter)
oven = [cake]


o= [(2+500+0.5)*(12+2)]

What if I want more eggs in my cake? What if I want a cake without sugar?
If you are just writing the code for your own projects, none of this matters much, but if you want your code to be useful to other people you have to make it accessible.

Have you tried using a program like PYCharm? I’ve been using PyCharm lately and it’s great for giving you some help with style guidelines and helping to keep your code clean and accessible. At first I didn’t like it because it’s more comfortable to write code in the same window as your game, but after a while it makes it much easier to keep everything organized, especially if you have multiple scripts. You can also collapse sections you’re not working on and just focus on what you need. You can set it up for auto completion too, so you don’t have to write everything out in full, or do refactoring really easily by switching out variables all at the same time.

I understand about the style stuff Smoking_Mirror, I made this in kinda a ‘proto-typing’ sprint

I am pretty sure I can make it use less logic and with easier to read code.

Yeah, a lot of my working scripts are pretty terrible to read through. :slight_smile: I just write and run.