Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by varunvp · May 21, 2016 at 05:47 PM · scripting problemnamespacefolderaccessing scriptssubclass

Script created in namespace has limited access to everything

Hey guys, I am using the UnitySteer package, and it has a set of steering behaviours contained in a folder/namespace. I want to add one of my own steering behaviours in this folder. Problem is, that any script created in this has limited access to everything. Heck, even MonoBehaviour 'does not exist in this context'! Due to this I am not able to derive from another class in the namespace which I so much need! The only way now is to edit one of the existing behaviours/scripts!

What am I doing wrong? Is there anything I have to do to gain access to namespaces?I just used the same format as all the other scripts were having.

Here is the link to the package (https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwjmtpD_x-vMAhVFOI8KHVgkDMgQFggcMAA&url=https%3A%2F%2Fgithub.com%2Fricardojmendez%2FUnitySteer&usg=AFQjCNH52VI_VPHwuemKoIJBWuWvlM-gpw&sig2=pG1rIahefmhaI2D-xmwOzw)

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 Oribow · May 22, 2016 at 01:03 AM 0
Share

Could you share the important part of the code? (Where you want to add something)

avatar image varunvp Oribow · May 22, 2016 at 09:12 AM 0
Share

Thanks for the reply Oribow. Fortunately(or unfortunately,) all it took was 2 restarts for that problem to be solved. However, I'll post the code in my answer.

1 Reply

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

Answer by varunvp · May 22, 2016 at 09:14 AM

It took 2(!) restarts, each 6 hours apart, to get it working. Don't know what happens to MonoDevelop sometimes...

Here is the code.

 using UnityEngine;
         
         namespace UnitySteer.Behaviors
         {
             [AddComponentMenu("UnitySteer/Steer/... for Obstacles")]
             public class SteerForObstacles : Steering
             {
                 public LayerMask m_LayerMask;
                 
                 // Bounding sphere radius
                 public float m_BoundingSphereRadius = 1;
                 
                 // Obstacle max distance
                 public float m_ObstacleMaxDistance = 10;
                 
                 // Steering force conservation after avoiding
                 [Range(0.1f, 0.9f)]
                 public float m_SteeringForceConservation = 0.9f;
                 
                 // Steering force conservation duration
                 public float m_SteeringForceConservationDuration = 1;
                 
                 // Max floor angle
                 [Range(0, 90)]
                 public float m_MaxFloorAngle = 45;
                 
                 // Steering force conservation timer
                 private float m_SteeringForceConservationTimer = 0;
                 
                 // Old valid steering force
                 private Vector3 m_OldValidSteeringForce = Vector3.zero;
                 
                 // Desired velocity
                 private Vector3 m_DesiredVelocity = Vector3.zero;
                         
                 protected override Vector3 CalculateForce()
                 {
                     Vector3 SteeringForce;
                     Ray ray = new Ray(transform.position, transform.forward);
                     RaycastHit hitInfo;
                     Vector3 avoidanceForce = Vector3.zero;
                     
                     // Calculate avoidance force
                     if (Physics.SphereCast(ray, m_BoundingSphereRadius, out hitInfo, m_ObstacleMaxDistance, m_LayerMask))
                     {
                         if (Vector3.Angle(hitInfo.normal, transform.up) > m_MaxFloorAngle)
                         {
                             avoidanceForce = Vector3.Reflect(Vehicle.Velocity, hitInfo.normal);
                             
                             if (Vector3.Dot(avoidanceForce, Vehicle.Velocity) < -0.9f)
                             {
                                 avoidanceForce = transform.right;
                             }
                         }
                     }
                     
                     if (avoidanceForce != Vector3.zero)
                     {
                         // Calculate desired velocity
         //                m_DesiredVelocity = (avoidanceForce).normalized * Vehicle.MaxSpeed;
                         m_DesiredVelocity = (avoidanceForce);
                             
                         // Calculate steering force
                         SteeringForce = m_DesiredVelocity - Vehicle.Velocity;
                         m_OldValidSteeringForce = SteeringForce;
                         m_SteeringForceConservationTimer = 0;
                     }
                     else
                     {
                         SteeringForce = Vector3.zero;
         
                         SteeringForce = SteeringForce * m_SteeringForceConservation;
         
                         m_SteeringForceConservationTimer += Time.deltaTime;
         
                         if (m_SteeringForceConservationTimer > m_SteeringForceConservationDuration)
                         {
                             m_SteeringForceConservationTimer = m_SteeringForceConservationDuration;
                         }
         
                         float ratio = 1 - (m_SteeringForceConservationTimer / m_SteeringForceConservationDuration);
                         SteeringForce = m_OldValidSteeringForce * ratio;
                     }
                     return SteeringForce;
                 }
         
                 void OnDrawGizmos()
                 {
                     Gizmos.color = Color.magenta;
                     Gizmos.DrawWireSphere(transform.position, m_BoundingSphereRadius);
                     Gizmos.DrawLine(transform.position, transform.position + transform.forward * m_ObstacleMaxDistance);
                     
                     if (Vehicle == null)
                     {
                         return;
                     }
                     
                     Gizmos.color = Color.green;
                     Gizmos.DrawLine(transform.position, transform.position + m_DesiredVelocity);
                     
                     //if (SteeringCore.Rigidbody != null)
                     {
                         Gizmos.color = Color.red;
                         Gizmos.DrawLine(transform.position, transform.position + Vehicle.Velocity);
                     }
                 }
         
             }
         }

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Issues with namespaces and folder structure 1 Answer

2 error messages i can't seem to fix (CS0101 and CS0111) 1 Answer

Why is the code below not setting the value for the timer? 0 Answers

MyClockScript.cs(6,14): error CS0101: The namespace `global::' already contains a definition for `MyClockScript' 1 Answer

Cant get booleans and floats from other scripts 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