I modified the pulse function to return a vector 3 instead of a float. For now, I’ll just be using a single pulse value calculated from a body’s average scale.

My scaling algorithm contained a bug that had yet to manifest in an actual issue. I had been calculating the previous distance between two bodies and using that distance to add or remove an attractor to/from a player’s list of attractors. The issue was that the previous distance was a global variable, so it got set independently of which two bodies were being compared. Somehow, though, my code still worked. Funnier still, I realized that I didn’t even need to incorporate two bodies’ previous distance within my logic because I could simply determine whether a given body’s attractors list contained a specified body before adding to or removing from it.

The next thing I needed to do was separate my scaling function from my gravity function. This would allow me to have body pulsation work regardless of whether a body entered the orbit of another.

Alas, I’ve discovered an interesting new bug. Compare the left and right captures below:

Notice how in the right capture, the merged bodies have differently-sized attraction radii. The mere presence of a third body caused the two merging bodies to scale to different sizes. The good news was that the scale issue happened in absence of any interaction with the pink sphere, showing that this was not a physics issue. Instead, this was caused by incorrectly setting the scale of a body within my script’s main for loop. When scaling, my code did not discriminate between bodies with no attractors and bodies with one or more attractors. I had to make sure to set the scale value outside the if/else statement containing the code controlling a body’s list of attractors. This ended up being a case of reordering code rather than rewriting it.

My next goal is to control the pulse speed based on the jerk (change in acceleration) of a body. Right now, I’m stumped on how to do this, because in my pulsation function, small changes in pulseSpeed result in large changes in position result in large changes in position.

float pulseSize = playerPulseAmt * Mathf.Sin(pulseSpeed * (Time.fixedTime + player.offset));

I need a way to smoothly interpolate changes in acceleration. Right now, however, even changes in velocity are tough for me to calculate. At least there is no drag in play.


Tags: gamedev unity physics vfx scripting debugging algorithms