Sinusoidal Enemy Movement

Had a lot of fun this morning experimenting with producing curvy unpredictable enemy movement in the spirit of Galaga.

All this variation was produced with a single line of code referencing the Mathf.sin function for the x and y translation, and feeding their own values back into the sin function. You can see some of the other variations I experimented with commented out in the code below also.

This was expected to produce some unexpected movement, and it did just that. I needed to make sure the Sin function was taking a value in the range of a radian. Crossing the x and y position values back into the Sin function produced my favorite motion so far (Putting position.x in the Sin function for the Y axis, and visa versa). I used an offset value to keep the enemies flowing rather than just hovering. Could play with this much more, and may come back to this for developing new enemies or wave variation.

I had a bunch of frustration with the camera shake effect earlier. Part of this was due to a coroutine loop where I was using Time.time, and it never was changing. Turns out it is calculated by frame, and I needed to use the more absolute time = Time.realtimeSinceStartup. Wrote several different versions of this routine, eventually removing the Time all together and experimenting with different yields.

Working on my “Wave” system now, having some issues with the timing section again and which Time variable to count. Decided I wanted it to be governed by the number of enemies in a wave instead of a hard time in the end, so will be reworking it like that so I can increase the enemies per wave.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
JEFF SHAW

JEFF SHAW

10 Followers

Unity VR Developer (VRX Virtual Reality Experiences VRX)