glide with the wind.

I’m building a game witch you throw a paper planes to a target. For the plane throwing I used rigidbody.AddForce.

I trying to add a wind that will affect the plane when it flying and I don’t know where to start or if it even posible.

Does anyone can help me with it?
Sorry for poor english.

You could use trigger collider areas to set something like a wind zone up.

wind force on character controller take a look at the stuff on there and adapt those ideas to your plane rather than using character controller.

EDIT :

Heres something to get you started.

Add this to you’re paper-plane’s movement script. →

private var myRigid : Rigidbody ; //used to cache the planes rigidbody
private var inWind : boolean = false ;
@HideInInspector
var windScript : WindScript ;
var windObjectTag : String = "MyWindObjectsTag" ; //set this in the inspector to
                                                  //whatever you tag your wind object as

 
//if you have a start() function, add this to it ; make one if you don't
function Start(){
   myRigid = rigidbody ;
}
 
//if you have your plane movement in FixedUpdat() , add this to that area
function FixedUpdate(){
   if(inWind && windScript!=null){ //if we're in the wind
     BlowMe(); 
   }
}
 
function BlowMe(){
   myRigid.AddForce(windScript.wind) ; //add force from the windscript
}
 
//if you have on ontriggerenter() on your plane already, just add this to it
function OnTriggerEnter(hit : Collider){
   if(hit.collider.CompareTag(windObjectTag)){
      inWind = true ;
      windScript = hit.gameObject.GetComponent(WindScript) as WindScript ;
   }
}
 
//if you have ontriggerexit on your plane already, add this to that function
function OnTriggerExit(hit : Collider){
   if(hit.collider.CompareTag(windObjectTag)){
      inWind = false ;
      windScript = null ;
   }
}

Now, make a new Empty game Object… name it whatever, then tag it whatever you want your wind to be tagged as, and make sure you set on the inspector the script above to be looking for that tag in ‘windObjectTag’ …

Give that empty object a primitive collider (sphere,box,etc) and size it however large you want your windzone to be. Mark it’s collider as ‘isTrigger’ in the checkbox.

Make a new javascript file. Name it “WindScript”.
Add this single line to the WindScript →

var wind : Vector3 ; 

.... now, attach that script to your new empty wind object you just made, then in the inspector set the variable values of 'wind' on whatever axis with whatever force etc...

Repeat this as necessary for however many windzones you want with whatever forces etc you want them to have.

Note : the ‘wind’ will be adding force in global/world relation, NOT in relation to your object/plane’s local rotation.

Hi there,…

This script is what I really need. I’m afraid I don’t know much about coding, but I learn as I go along.

Problem is I keep getting a compiler error. I think I did exactly as written.

I appended the script to the default CharacterMotor script as said.

But the compiler keep saying that “the name WindScript does not denote a valid type (not found)”. I did add the windscript named WindScript as mentioned to an empty gameobject wit a box collider. I also added a custom tag: “Wind” to that object and put Wind in the original script snippet above… Sry, but I don’t know what I do wrong :frowning:

Hi there,…

This script is what I really need. I’m afraid I don’t know much about coding, but I learn as I go along.

Problem is I keep getting a compiler error. I think I did exactly as written.

I appended the script to the default CharacterMotor script as said.

But the compiler keep saying that “the name WindScript does not denote a valid type (not found)”. I did add the windscript named WindScript as mentioned to an empty gameobject wit a box collider. I also added a custom tag: “Wind” to that object and put Wind in the original script snippet above… Sry, but I don’t know what I do wrong :frowning:

I m Stuck in Rotation Of Plane

Vector3 dir = m_Rb.velocity;

//Debug.Log (""+dir);

float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;

transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

with this i m geting rotation but not correct , thanks