- Home /
Wave formula(s) (math)
Hey, i am making a game where you control a ship on a rough ocean and have to fight the waves and other ships.
I have the wave "simulation" working fine, that is using overlapping sinus waves. However, pure sinus waves looks a bit dull, and i was wondering if anyone knows any other mathematical approaches for creating "sinus-like" waves? Maybe some with a sharper top than a sinus wave, and some tilting forward like waves that are about to collapse.
Also, as it currently stands waves have a center and moves in one specific direction. I would like the ability to create a wave which moves out from a center, like when you throw a rock into water in real life. Do anyone know how to do this?
Thanks for any answers! :)
Answer by fafase · Apr 02, 2014 at 07:28 PM
Triangle wave may be your solution: http://en.wikipedia.org/wiki/Triangle_wave
but when you will see the equation, I guess you will be happy with your sin wave.
Other solution is just to move left to right and downward:
float maxLeft, maxRight;
bool direction = true;
void Update()
{
Vector3 pos = transform.position;
pos.y -= speed *Time.deltaTime;
if(direction)
{
pos.x += speed *Time.deltaTime;
if(pos.x >= maxRight)direction = false;
}
else
{
pos.x -= speed *Time.deltaTime;
if(pos.x <= maxLeft)direction = true;
}
}
You could use some more technical way with MoveTowards and placing game objects to mark the target points but this one above is understandable.
For the ripple effect, maybe exa$$anonymous$$ing the code in this demo may help (scroll down to UnityRippleTest for Unity project download link).
Your answer
Follow this Question
Related Questions
How can I make water waves ? 1 Answer
Ocean shader that works for mobile devices 0 Answers
Water scale 1 Answer
Different wave speeds 1 Answer
Best method to make an Ocean? 2 Answers