- Home /
Question by
potuk · Jul 01, 2015 at 10:25 AM ·
proceduralwaterwater4
Procedural water generation
I'm looking for suggestions on how to get started with procedurally generating water4. I've been unable to find any examples of this so far. Specifically, I'm aiming to have an airplane fly across open ocean and have water appear and disappear as needed so it looks like a continuous open ocean.
Comment
Answer by etopsirhc · Jul 01, 2015 at 11:58 AM
one way to do this would be to have a plane set at where the water level would be, but locked to the position of the airplanes x and z. then just animate the texture to scroll across the water plane at the rate and direction of the airplane.
i have a script that scrolls a texture on a RawImage UI canvas. it would take some editing, but you could use that as a base if you want to take that route.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ImageSroller : MonoBehaviour {
public bool lockEdges = true;
public float rate = 1f;
public KeyCode positve;
public KeyCode negitive;
Vector2 offset = new Vector2(0f,0f);
public Vector2 direction = new Vector2(0f,0f);
public RawImage picture;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float dir = 0f;
if (Input.GetKey(positve)){
dir += rate;
}
if (Input.GetKey(negitive)){
dir -= rate;
}
Rect r = picture.uvRect;
offset.x = (offset.x+(direction.x*dir)*Time.deltaTime)%1;
offset.y = (offset.y+(direction.y*dir)*Time.deltaTime)%1;
if (lockEdges){
if (offset.x >= 1-picture.uvRect.width){
offset.x = 1-picture.uvRect.width;
}
if (offset.y >= 1-picture.uvRect.height){
offset.y = 1-picture.uvRect.height;
}
if (offset.x <= 0){
offset.x = 0;
}
if (offset.y <= 0){
offset.y = 0;
}
}
r.position = offset;
picture.uvRect = r;
}
}