• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by kaparov · Feb 24, 2014 at 04:25 PM · flyingisland-demo

Changing the seagull fly path in the island demo, from point A to B

I’m using the island demo, and I want to manipulate the flaying path of the seagull, so that I can determinate a flying line from point A to point B. The actual script make the seagulls fly in a circle with a determinated speed and radius. Here is the script, tank you for any help:

 #pragma strict
 #pragma implicit
 #pragma downcast
 
 var flySpeed = 15.00;
 var highFlyHeight = 80.00;
 var normalFlyHeight = 40.00;
 var lowFlyHeight = 20.00;
 var flyDownSpeed = 0.10;
 var circleRadius = 60.00;
 var circleSpeed = 0.20;
 var circleTime = 15.00;
 var awayTime = 20.00;
 
 var offset : Vector3;
 
 private var myT : Transform;
 private var player : Transform;
 private var awayDir : Vector3;
 private var flyHeight = 0.00;
 private var col : Collider;
 private var hit : RaycastHit;
  = 0.00;
 private var lastHeight = 0.00;
 private var height = 0.00;
 private var terrainSize : Vector3;
 private var terrainData : TerrainData;
 
 private var dTime = 0.1;
 
 function Start ()
 {
     terrainData = Terrain.activeTerrain.terrainData;
     terrainSize = terrainData.size;
     col = Terrain.activeTerrain.collider;
     myT = transform;
     player = gameObject.FindWithTag("Player").transform;
     MainRoutine();    
 }
 
 function MainRoutine ()
 {
     while(true)
     {
         yield ReturnToPlayer();
         yield CirclePlayer();
         yield FlyAway();
     }
 }
 
 function ReturnToPlayer()
 {
     distToTarget = 100.00;
     while(distToTarget > 10)
     {
         toPlayer = player.position - myT.position;
         toPlayer.y = 0;
         distToTarget = toPlayer.magnitude;
         if(distToTarget > 0) targetPos = transform.position + ((toPlayer / distToTarget) * 10);
         else targetPos = Vector3.zero;
         
         targetPos.y = terrainData.GetInterpolatedHeight(targetPos.x / terrainSize.x, targetPos.z / terrainSize.z);
         normal = terrainData.GetInterpolatedNormal(targetPos.x / terrainSize.x, targetPos.z / terrainSize.z);
         offset = Vector3(normal.x * 40, 0, normal.z * 40);
         
         flyHeight = (distToTarget > 80) ? highFlyHeight : lowFlyHeight;
         if(distToTarget > 0) Move(targetPos - transform.position);
         yield WaitForSeconds(dTime);    
     }    
 }
 
 function CirclePlayer()
 {
     var time = 0.00;
     while(time < circleTime)
     {
         circlingPos = player.position + Vector3(Mathf.Cos(Time.time * circleSpeed) * circleRadius, 0, Mathf.Sin(Time.time * circleSpeed) * circleRadius);
         circlingPos.y = terrainData.GetInterpolatedHeight(circlingPos.x / terrainSize.x, circlingPos.z / terrainSize.z);
         normal = terrainData.GetInterpolatedNormal(circlingPos.x / terrainSize.x, circlingPos.z / terrainSize.z);
         offset = Vector3(normal.x * 40, 0, normal.z * 40);
 
         flyHeight = normalFlyHeight;
         Move(circlingPos - myT.position);
         time += dTime;
         yield WaitForSeconds(dTime);    
     }    
 }
 
 function FlyAway()
 {
     radians = Random.value * 2 * Mathf.PI;
     awayDir = Vector3(Mathf.Cos(radians), 0, Mathf.Sin(radians));
     var time = 0.00;
     while(time < awayTime)
     {
         away = player.position + (awayDir * 1000);
         away.y = 0;
         
         toAway = away - transform.position;
         
         distToTarget = toAway.magnitude;
         if(distToTarget > 0) targetPos = transform.position + ((toAway / distToTarget) * 10);
         else targetPos = Vector3.zero;
         
         targetPos.y = terrainData.GetInterpolatedHeight(targetPos.x / terrainSize.x, targetPos.z / terrainSize.z);
         normal = terrainData.GetInterpolatedNormal(targetPos.x / terrainSize.x, targetPos.z / terrainSize.z);
         offset = Vector3(normal.x * 40, 0, normal.z * 40);
         
         flyHeight = highFlyHeight;
         Move(targetPos - transform.position);
         time += dTime;
         yield WaitForSeconds(dTime);    
     }    
 }
 
 function Move (delta : Vector3)
 {
     delta.y = 0;
     delta = delta.normalized * flySpeed * dTime;
     newPos = Vector3(myT.position.x + delta.x, 1000, myT.position.z + delta.z);
     if(col.Raycast(Ray(newPos, -Vector3.up), hit, 2000)) newHeight = hit.point.y;
     else newHeight = 0.00;
     if(newHeight < lastHeight) height = Mathf.Lerp(height, newHeight, flyDownSpeed * dTime);
     else height = newHeight;
     lastHeight = newHeight;
     myT.position = Vector3(newPos.x, Mathf.Clamp(height, 35.28, 1000.00) + flyHeight, newPos.z);
 }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fafase · Feb 25, 2014 at 12:27 PM 0
Share

You need to change the move method to go from point A to point B ins$$anonymous$$d of going in circle. Or are you asking for the script as well?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Seagulls flying through models ? 1 Answer

unity 3.4 having trouble with islanddemo 0 Answers

Character Flight 1 Answer

Player bouncing off issue 1 Answer

How to stop shadows from flying? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges