While researching singletons yesterday, I stumbled upon scriptable objects. I liked the idea of having interchangeable configuration settings for my scene parameters and figured I’d try to implement a solution.
I moved all my scene parameters to a scriptable object class and then declared a public scriptable object variable in my scene controller. In each of my scripts that inherited the scene controller instance, I referenced the scriptable object in my scene controller. Now, all my scene control parameters existed in the scriptable object rather than in the controller script. Aside from allowing me to make multiple scene control configurations, this has the added benefit of seriously cleaning up my scene controller script, but the drawback of not reverting variables to previous settings after exiting play mode. To compensate for that negative, I made a backup of my working settings.
This pattern may get tiring later on, or I might just Ctrl+Z my way around instead of doing backups. (I’m smart enough to know I should always do backups.) Either way, this was a fun, educational exercise.
I have a new idea for scaling a spherical body, and I think I may even be able to use it to further refine the force added from the player’s hand motion.
First, I’m going to add colliders to the hands and sphere. Then, each frame, for each hand, I’ll raycast from the center of the hand along its velocity vector in both directions (with the velocity and opposite the velocity). If a ray hits both the sphere and the other hand, then I’ll scale the sphere by a ratio based on the hand’s velocity and its distance from the other hand. This way, when I move one hand towards the other, the sphere will decrease in size, and the reverse will occur when the hands move away from each other. But, when the hand is moving in a direction not directly in line with the sphere and opposite hand, its motion will have no effect on scale.



Tags: unity gamedev scriptableobject scripting physics raycasting 3d