Gotta be honest, I didn’t expect to work on this project today since I just started my new job. But, because my boss was busy, I spent time getting motion-based pulsation working.

I created a new script called “Player Scaler”. I knew that since I’d be modifying a body’s unscaled size, I wouldn’t need to worry about conflicting with the other pulsation algorithm. Speaking of, I needed to differentiate between the default pulsation and this new motion-based one. I couldn’t think of an adjective to describe the default pulsation (default isn’t a good word for it) so I asked ChatGPT for assistance.

Now that I’d differentiated between my existing intrinsic pulsation and the motion-based pulsation, it was time to work on my script.

In said script, I check the magnitude of a player’s left and right hand velocities once at a time to see if they’re above a minimum velocity. For user experience purposes, I didn’t want to scale the body when a player is barely moving, but I also had to add the minimum velocity threshold to avoid a weird error error that turned up when the velocity vector of a hand is 0. You can’t normalize a vector with no size.

Anyways, I create two rays for each hand, one going along its velocity and another along its negative velocity. I cast the rays and check to see if a ray hits both the body’s collider and the opposite hand’s collider. When that happens, I scale the body based on the hand’s velocity projected onto a vector created from the distance between the hands. If the hand is moving away from the body, I increase the body’s size. I do the opposite if the hand moves toward the body. I added a minimum unscaled size property to the player constructor to make sure my player doesn’t disappear.

I added a curve-based damper to taper the scaling based on distance between the hands. When the hands get really close, I don’t want to scale the body much at all, and when they get further away, I want to decrease the scaling factor gradually. Below, the Gif on the right shows the scaling rate using the curve on the left.

Now, it’s time for me to combine my meshes again.


Tags: gamedev unity vfx scripting physics ux