Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 kathir · Oct 29, 2012 at 03:16 PM · c#collisionaipathfinding

Movement around a huge object by avoiding obstacles

Hello People, I am working on a game where a NonPlayable Character takes a journey across a trunk of the tree.


I have a huge object in the middle. It's height across the y axis is huge and it is the trunk. So, I could say it is like a big tree and small bugs flying around it. At any point, I would like the bug to travel around the tree in a spectacular fashion and hence the camera would be following it. It is completely automated.

The calculation for the path has to be during runtime with the constraint being to avoid the branches & trunk. Mostly the motion would be circular.


What would be the efficient way or the best approach to achieve it?

Thank you and appreciate your help.

Comment
Add comment · Show 2
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 Karsnen_2 · Oct 29, 2012 at 03:25 PM 0
Share

Hmmm... I am not sure but I think it is possible through iTween. But if anyone else, could clarify this go ahead.

avatar image kathir · Oct 29, 2012 at 03:32 PM 0
Share

karsnen. I am not sure about it yet. I heard it is not great for garbage collection.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Montraydavis · Oct 29, 2012 at 03:47 PM

I created something similar with Raycasts, but, it will require you to do a lot of polishing to get the effect to look very realistic. But none the less, the object will avoid obstacles, but requires a Target be set . . .

With having that said, I suggest using this only as a starting point. It contains most of what you need for a fully fledged obstacle avoidance .

Currently, it supports obstacle avoidance forward, left, and right, but does not work if there are colliders on both the left and right side. . . You can change this, and fix it up a bit though.

PS: Feel free to use this script in whatever way you want .

Here you go:

 #pragma strict
 
 var Target : GameObject ;
 
 var TargetHit : RaycastHit ;
 var TargetHitLeft : RaycastHit ;
 var TargetHitBack : RaycastHit ;
 
 
 
 class _VisionRaycastHit{
     var Back : RaycastHit ;
     var Front : RaycastHit ;
     var Left : RaycastHit ;
     var Right : RaycastHit;
 }
 
 class _VisionDirection {
     var Left : float = 0 ;
     var Right : float = 0 ;
     
     var LeftActive : boolean = false ;
     var RightActive : boolean = false ;
 }
 
 class _Vision {
     var Back : boolean = false ;
     var Front : boolean = false ;
     var Left : boolean = false ;
     var Right : boolean = false ;
     
     var EaseOut : float = 2 ; 
     
     var Hit : _VisionRaycastHit ;
     
     var VisionDirection : _VisionDirection ;
 }
 
 var Vision : _Vision = new _Vision ( ) ;
 
 
 function Start () {
 
 }
 
 function Update () {
 
     Vision.Front = Physics.Raycast(Vector3(transform.position.x, transform.position.y+1, transform.position.z), transform.TransformDirection( Vector3.forward ), Vision.Hit.Front, 15);
     Vision.Back = Physics.Raycast(Vector3(transform.position.x, transform.position.y+1, transform.position.z), transform.TransformDirection( Vector3.back ), Vision.Hit.Back, 15);
     Vision.Left = Physics.Raycast(Vector3(transform.position.x, transform.position.y+1, transform.position.z), transform.TransformDirection( Vector3.left ), Vision.Hit.Left, 15);
     Vision.Right = Physics.Raycast(Vector3(transform.position.x, transform.position.y+1, transform.position.z), transform.TransformDirection( Vector3.right ), Vision.Hit.Right, 15);
     //VisionLeft = Physics.Raycast(Vector3(transform.position.x, transform.position.y+1, transform.position.z), transform.TransformDirection( Vector3.left), TargetHitLeft, 15);
     //VisionBack = Physics.Raycast(Vector3(transform.position.x, transform.position.y+1, transform.position.z), transform.TransformDirection( Vector3.forward ), TargetHitBack, 15);
     var Direction : Vector3 ;
     
     Direction = ( transform.TransformDirection ( Vector3.forward ) ) ;
     
     if ( Vision.Front )
     {
         if ( Vision.Left )
         {
             Vision.VisionDirection.Right += 5 * Time.deltaTime ;
             Vision.VisionDirection.RightActive = true ;
         }else if ( Vision.Right ){
             Vision.VisionDirection.Left += 5 * Time.deltaTime ;
             Vision.VisionDirection.LeftActive = true ;
         }
         
         if ( Vision.VisionDirection.LeftActive ){
             transform.rotation = Quaternion.Slerp ( transform.rotation, Quaternion.LookRotation ( - ( transform.position - Vector3(Target.transform.position.x-Vision.VisionDirection.Left , Target.transform.position.y, Target.transform.position.z) ) ), 1 * Time.deltaTime ) ;
             //Vision.EaseOut = 245 ;
     
         }else if ( Vision.VisionDirection.RightActive ){ // If Turning Right
             transform.rotation = Quaternion.Slerp ( transform.rotation, Quaternion.LookRotation ( - ( transform.position - Vector3(Target.transform.position.x+Vision.VisionDirection.Right , Target.transform.position.y, Target.transform.position.z) ) ), 1 * Time.deltaTime ) ;
             Vision.EaseOut = 2 ;
     
         }else{ // Turn Right By Default 
             transform.rotation = Quaternion.Slerp ( transform.rotation, Quaternion.LookRotation ( - ( transform.position - Vector3(Target.transform.position.x+Vision.VisionDirection.Right , Target.transform.position.y, Target.transform.position.z) ) ), 1 * Time.deltaTime ) ;
             Vision.EaseOut = 2 ;
     
         }
     }else{
         
         transform.position += Direction * Time.deltaTime ; 
         if ( Vision.Right == false && Vision.Left == false ){
             if ( Mathf.Ceil ( Vision.EaseOut ) == 0  ){
                 Vision.VisionDirection.LeftActive = false ;
                 Vision.VisionDirection.RightActive = false ;
             }else{
                 Vision.EaseOut -= 1 * Time.deltaTime ;
             }
         }
         
         if ( !Vision.VisionDirection.RightActive && !Vision.VisionDirection.LeftActive ){
             
             ///transform.rotation = Quaternion.Slerp ( transform.rotation, Quaternion.LookRotation ( - ( transform.position - Vector3(Target.transform.position.x , Target.transform.position.y, Target.transform.position.z) ) ), 1 * Time.deltaTime ) ;
         }
         
         if ( Vision.Right )
         {
             Vision.EaseOut = 2 ;
         }else if ( Vision.Left ){
             Vision.EaseOut = 2 ;
         }
     }
 }
Comment
Add comment · Show 2 · Share
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 kathir · Oct 29, 2012 at 04:10 PM 0
Share

$$anonymous$$ontraydavis : I am going thro it right now. Will update you. Appreciate your help.

avatar image Montraydavis · Oct 29, 2012 at 04:30 PM 0
Share

No problem. You are welcome. If this works for you, feel free to thumbs up, or mark this as answered. Thank you for using Unity :)

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.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Have falling object exit from a collider after collision? 2 Answers

Evade a Collider on Vector3.forward 3 Answers

A* Pathfinding Bug: Dictionary Key Not Found Exception 1 Answer

Make player not be seen by AI, when player in foilage and shadows. 1 Answer

Collider Vision AI question. Solved! 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges