Cant get script to effect constantForce on object

I am trying to change the constant force on a game object. I have a object I want to blow around and change the wind randomly. I have a game object I select in unity and it has a constantForce and a Rigid body applied. The script below does not change the force in fact the constant force does not move the object when the script is applied. But the constantForce on the object does move it without the script. Any Ideas ? ( dont know if this should on the transform or the object so Im doing both, I have tried them separately but still no effect)

var windPeriodCount : int = 1;
private var windChange : int = 0;
private var ifWindy : boolean = false;
private var itsWindy : int = 1 ;
private var windStrength : int = 1;
private var windDirection : Vector3;
private var newWindDirection : Vector3;
private var windOldDirection : Vector3;
private var windNoiseStrength : int = 1;
private var windNoiseDirection : Vector3;
private var windVectorXRandom : int = 0;
private var windVectorYRandom : int = 0;
private var windVectorZRandom : int = 0;
var smooth : float = 0.5;
var ball : GameObject;
var ballTrans : Transform;
var customSkin :GUISkin;





function start()
{
	windPeriodCount = Random.Range(1, 4);
	windPeriodCount = (windPeriodCount * 10) + Time.timeSinceLevelLoad;
	windChange = Random.Range(1, 4);
	itsWindy = Random.Range(0, 5);
	windDirection = Vector3(-6,0,0);
	newWindDirection = 	windDirection;
	windOldDirection = windDirection;
	ballTrans.constantForce.force = Vector3(-600,0,0);
	ball.constantForce.force = Vector3(-600,0,0);


	
}


function Update () {
	
	windStrengthProc();
	windDirectionProc();
	windyTime();
	ballTrans.constantForce.force = windDirection;
	ball.constantForce.force = windDirection;

	
	
	
}



function windyTime()
{
	windVectorXRandom = Random.Range(-1, 2);
	windVectorYRandom = Random.Range(-1, 2);
	windVectorZRandom = Random.Range(-1, 2);
	windPeriod = windPeriodCount - Time.timeSinceLevelLoad;
			if (windPeriod < 1)
				{
					windPeriodCount = Random.Range(1, 4);
					windPeriodCount = (windPeriodCount * 10) + Time.timeSinceLevelLoad;
					windChange = Random.Range(1, 4);
					itsWindy = Random.Range(0, 5);
					if (itsWindy == 1)
					{
						ifWindy = true;
						newWindDirection = Vector3(windVectorXRandom * windStrength,0,windVectorZRandom * windStrength);					
					}
					else
					{
						ifWindy = false;
						windOldDirection = windDirection;
					}
		
				}
	
	
}

function windStrengthProc()

{
	if (ifWindy ==true)
	{
		windStrength = Random.Range(1, 4);
		windStrength = windStrength * 500;
	}

	
}

function windDirectionProc()
{
	
	
	windDirection = newWindDirection;
	
}




function OnGUI()
{
	GUI.skin = customSkin;
	GUI.Label (Rect(60,100,100,40), "wind direction : " + windStrength.ToString());
	GUI.Label (Rect(60,120,100,40), "If windy : " + ifWindy.ToString());

}

I know its New Year so Happy New Year to all. But still want your brilliant advice :slight_smile:

Have you tried playing around w. AddForce on the transform ? Saw this in a couple of the example projects methinks

/Christian

Yes there was still no effect.

Are “ball” and “ballTrans” referring to the same object? If so, you don’t need to set the constant force for both of them - just pick one and use that. Also, try using a print statement, just after the call to WindyTime, to see the value of the force vector. It might not be getting set up with the right value.