Sunday, October 29, 2017

Ground-Up Rewrite

hey all,

I have been working to integrate lenses and destructible objects into the framework I've already developed, but this weekend I ran into a snag. As I was experimenting with moving and rotating my lens, I realized that the calculation for how light refracts through it was fundamentally flawed. Now matter how I rotated the lens, light was always bent down. The kicker to this was that I had basically copied the code I used for calculating refraction through a prism, which meant that those calculations were fundamentally flawed too. So over the whole weekend I have rewritten the refraction algorithms and calculations, greatly simplifying them and correcting the errors from before. I've also been correcting some small positional errors throughout the whole code base.

With these fixes and changes in place, the next week's work will focus on redesigning the first 18 levels, and on expanding the game with more puzzles to solve.

Cheers,

Sunday, October 22, 2017

Particularly Wavy Black Hole Update

hey all,
I've continued working on the black hole effect, and now, after several weeks of work I have something that I like quite a bit. This effect is, in my opinion, almost ready to be included in the game. The main catch is that right now I am not checking for any collisions within the influence of the black hole itself. There is now really nice way of doing this, but I think I have an idea that might work.



The other update to the game is actually not visible at all, but should greatly increase performance. In previous versions, I would update the light every frame, even if nothing had changed. In the newest version, I have made use of a callback function on every moveable object. When the object is moved or rotated, the function notifies the light emitting object and the light is recalculated from the beginning. If no object gets moved, the light is not updated, which should have a lot of calculations each frame and make the game run much smoother.

There are one or two main updates I would like to make to the game before starting work on designing more levels, but these should be doable within the next two weeks (as the famous construction joke goes).


I'd also like to make the UI compatible with mobile devices, but that is a distant 3rd on my list of things to work on. In any case, here goes to successful game development.

Sunday, October 15, 2017

Particularly Wavy Updates

hey all,

I've spent the last week nailing down a black hole-like effect for Particularly Wavy. It is still extremely rough, and needs a lot of ironing out of details, bugs, and at the moment is probably very expensive in terms of processor use.


Vector3 gravityVec;
  float d;

  Vector3 accel = Vector3.zero;
  Vector3 previous = pos;
  float time = 0.05f;
  float diff = 0.1f;
  for (int i = 0; i < 150; i++)
  {

   gravityVec = center - previous;
   d = Vector3.Distance(center, previous);
   accel.x = blackHoleMass / (d * d * d * d * d);
   accel.y = blackHoleMass / (d * d * d * d * d);
   accel = Vector3.Scale(accel, gravityVec);
   vel += accel * time;
   previous += vel * time;

   if (i % 2 == 0)
   {
    tempList.Add(previous);
   }
   Debug.DrawLine(center, previous, Color.red, 1f);
   if (Vector3.Distance(previous, center) < rad + diff)
   {
    tempList.Add(previous);
    node.hitObject = go;
    hitHole = true;
    break;
   }
   else if (Vector3.Distance(previous, center) > blackHoleDistance + rad)
   {
    tempList.Add(previous);
    break;
   }
  }

I though it might be a bit fun to share some of the code that I've been working on to make this happen. To begin with, the acceleration is set to zero, the velocity is set to a normalized vector indicating the direction of travel multiplied by speed, and a starting position for the light to enter the influence of the black has been found. A time step of 0.05 seconds is used to simulate the physics.

In the loop, the acceleration is the first thing computed. This is found by subtracting the position vectors between the black hole and the light particle, then getting the distance between the previous position and the center of the black hole. Under this model, acceleration is proportional to the mass of the black hole divided by the distance to the 5th power. This acceleration is multiplied by the time step and added to the previous velocity to get the new velocity. Similarly, the new velocity is multiplied by the time step and added to the previous position to yield the new position.

If, while going through the loop, the new position is inside the radius of the black hole or is outside the influence zone of the black hole, we break out. From here, the new positions need to be applied to the line renderer's positions.

This is obviously not exactly how gravity works in the real world. For starters, it is proportional to the masses of the two objects divided by the square of the distance between them, Newton's famous relationship that Robert Hooke accused him of stealing. Of course, light particles have no mass, but their interaction with black holes is caused by the intense gravity actually curving space-time itself.