Quest: Floaty Boat Quest
Challenge: Rising Tide
Feel free to share your solutions, ideas and creations below. If you get stuck, you can find some ideas here for completing this challenge.
Quest: Floaty Boat Quest
Challenge: Rising Tide
Feel free to share your solutions, ideas and creations below. If you get stuck, you can find some ideas here for completing this challenge.
I have 3 different solutions to this. Make Wave was my first attempt, it just slerps the transform up and down, I think it works well enough and has the advantage that I totally understands how it works. The second uses Sin. Multiplying the time by half the “period” makes the cycle complete in “period” seconds. Can’t say I entirely say I understand how that works but it does use less code than the slerp.
The mesh deformation looks cool but I totally got all the code off the internet and don’t really understand it. baseHeight is an array of the starting vertices so I don’t know why whoever wrote it called it baseHeight. Its full of magic numbers because I didn’t really know what I was doing and was just tweaking. I’ve left it for now because of the sinking issue.
void MakeWave2()
{
Vector3[] vertices = new Vector3[baseHeight.Length];
for (int i = 0; i < vertices.Length; i++)
{
Vector3 vertex = baseHeight[i];
vertex.y += Mathf.Sin(Time.time * period + baseHeight[i].x + baseHeight[i].y + baseHeight[i].z) * 10;
vertex.y += Mathf.PerlinNoise(baseHeight[i].x + 1, baseHeight[i].y + Mathf.Sin(Time.time * 0.1f)) * 4f;
vertices[i] = vertex;
}
mesh.vertices = vertices;
mesh.RecalculateNormals();
}
void MakeWave3()
{
transform.position = Mathf.Sin(Time.time * (period/2)) * movementVector;
CurrentWaterLevel = transform.position.y;
}
void MakeWave () {
//TODO: Make the water plane move up and down to simulate a tide.
//Bonus: Make some actual waves by displacing the mesh vertices (Advanced and optional!).
cycles += Time.deltaTime*movementFactor;
if (cycles > period)
{
movementFactor = -1;
}
else if (cycles<0)
{
movementFactor = 1;
}
transform.position= transform.position = Vector3.Slerp(startingPos, startingPos+movementVector, cycles/period);
CurrentWaterLevel = transform.position.y;
}