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 SrBilyon · Sep 05, 2010 at 04:30 AM · raycastailevelfallingobstacle avoidance

Raycast to check for potential pitfalls

Currently I have my enemies moving around using Raycast obstacle avoidance. "if (checkObstacles)"

The code below steers the enemy away from obstacles. Right now, I'm trying to have my enemies check ahead and down to see if there isn't any thing there, and if so, steer the enemy away from an potential pit until he detects a surface.

The direction Vector is the enemy's movement, and this code basically "rotates" the enemy by manipulating the direction vector.

alt text

Right now, I am having trouble with both making the raycast shoot forward and down in the if statement that starts off "if (checkPitfalls)". The enemy doesn't acknowledge the lack of a raycast collision and just keeps running off the level.

     //First Offset where the ray should end up
     Vector3 pitRayOffset = new Vector3(0, 0, 1);
 
     //Then Shoot it down
     Vector3 pitCheckRay =  trans.TransformDirection(0, -2, 0);
     
     if (checkPitfalls)
     {
         Debug.DrawRay(trans.localPosition + pitRayOffset, (pitCheckRay) * 2, Color.cyan);
         RaycastHit groundCheck;
         if (!Physics.Raycast(trans.localPosition + pitRayOffset, pitCheckRay, out groundCheck, 2))
         {
             print("NO GROUND");
             Debug.DrawRay(trans.localPosition + pitRayOffset, (pitCheckRay) * .5f, Color.red);
             direction = -direction;//+= (direction.magnitude * groundCheck.normal) * (percision * Time.smoothDeltaTime);
         }/*raycast*/
      }/*for loop*/
     
     direction.Normalize();
     direction.y = _holdTheJump;
     steeringRays.Clear();

     Quaternion rot = Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z));
     trans.rotation = Quaternion.Slerp(trans.rotation, rot, 3 * Time.smoothDeltaTime);   


I edited the script down to where the problem lies. The offset for the ray isn't rotating correctly when the enemy moves, so it isn't offsetting correctly.

In a nutshell, the ray isn't facing the forward direction: [Topdown view] alt text

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Eric5h5 · Sep 05, 2010 at 06:31 AM

You can tag the boundaries with a unique tag, and use the results from FindGameObjectsWithTag to loop through each boundary with Physics.IgnoreCollision and the player, so the player will go through the boundaries but nothing else will.

Or use layer-based ignore collisions in Unity 3.

Comment
Add comment · Show 1 · 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 SrBilyon · Jun 02, 2012 at 09:40 PM 0
Share

To avoid confusion, this question has been redone since Eric Last answered it :)

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

No one has followed this question yet.

Related Questions

AI Avoiding Obstacles Problem 1 Answer

AI create path, help. 1 Answer

How can I find if a raycast has passed through two points? 2 Answers

without using NavMesh, How to avoid autonomous moving agents/obstacles 1 Answer

Problems with raycast obstacle avoidance 1 Answer


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