Global Wind System

Hi all,
I’ll describe what I’ve got, then what I’m aiming for.

I’ve created a four point wind system north, east, south and west (very basic). This is called at random but it doesnt change until called to. The speed of the wind will change slightly every so often at random. The wind effects the main game object once projected in the air. The wind is based on player’s facing position so if the wind is south facing it doesn’t matter where the player is, the wind will still be south facing.

What I need is a global wind system not a local system, ie the wind doesn’t follow players facing position. I’ve tried a few ways but seem to get bogged down so I’m stuck with a very basic scripting, this is a small part of one of the scripts.

static var windSpeed : int;

static var windDirection : String;

static var hitTrue : boolean = false;

private var power : int;

var golfBall : Transform;

private var randomAmount : int;

function Start ()
{

windSpeed = Random.Range(0,10);

windDirectionRandom = Random.Range(1,5);

}

function windChanging ()
{

windUpDown = Random.Range(1,3);

yield WaitForSeconds(waitWind);

if(windUpDown == 1 && windSpeed < 10)
{
	windSpeed = windSpeed + 1;
}

if(windUpDown == 2 && windSpeed > 1)
{
	windSpeed = windSpeed - 1;
}

windChange = true;

}

function Update ()
{

if(windDirectionRandom == 1)
{
	windDirection = "Left";
}

if(windDirectionRandom == 2)
{
	windDirection = "Right";
}

if(windDirectionRandom == 3)
{
	windDirection = "Forward";
}

if(windDirectionRandom == 4)
{
	windDirection = "Backward";
}

if(hitTrue == true)
{

if(putting.puttingTrue == false)
{

		randomAmount = Random.Range(25,75);
		randomAmount = randomAmount + 1500;
		power = powerbar.pointerSpeed * randomAmount;
		hitTrue = false;
		renderOff = true;
		camerasOn = true;
		putting.offRender = true;
		var drivingStart : Transform;
		drivingStart = Instantiate(golfBall, transform.position, transform.rotation);
		drivingStart.rigidbody.AddForce (drivingStart.transform.forward * power);
		SmoothFollow.Now = true;
	}

This is the object that is getting the wind effect script.

private var directionWind : String;

var power : int;

var stopWind : boolean = false;

var waiting : boolean = false;

var GolfObject: Transform;

private var fixedNow : boolean = false;

function Awake ()
{

cameraSet = gameObject.FindWithTag("Player").transform;

if(putting.puttingTrue == false)
{
	directionWind = driving.windDirection;
	power = driving.windSpeed * 5;

	if(directionWind == "Left")
	{
		transform.position.x -= power;
	}

	if(directionWind == "Right")
	{
		transform.position.x += power;
	}

	if(directionWind == "Forward")
	{
		transform.position.z += power * 5;
	}
}		

}

function update ()
{

if(putting.puttingTrue == false)
{
	power = driving.windSpeed * 5;

	if(stopWind == false)
	{

		if(waiting == false)
		{
			waiting = true;

			if(directionWind == "Left")
			{
				transform.position.x -= power;
			}

			if(directionWind == "Right")
			{
				transform.position.x += power;
			}

			if(directionWind == "Forward")
			{
				transform.position.z += power * 15;
			}

			if(directionWind == "Backward")
			{
				transform.position.z -= power * 15;
			}

			WaitingNow();
		}
	}
}			

}

function WaitingNow ()
{

yield WaitForSeconds(0.5);
waiting = false;

}

As you can see this is a very basic system (very raw). Any light on this will be very helpful.

Some of your variables in the wind script are static, then you are using the Start() function to initialize, taht’s your problem. You should use a static class, which doesn’t inherit from Monobehaviour, for the wind, create an Initialize function (or whatever name you want) instead of Start(), and call it in the other script which is actually attached to a GameObject. Same thing for the Update().

Or, don’t use static.

I don’t think you understand I didin’t explain to well. How do I work out the wind direction relative to the players position.