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 RaulG · Nov 13, 2014 at 05:03 AM · c#movementphysicsraycast

Vector3.Movetoward. Why does this work?

 void Update () 
         {
             moveDist = speed * Time.deltaTime;
     
             Vector3 posDir = AINodePoints [curIndex].transform.position - transform.position;
             Vector3 rotDir = Vector3.RotateTowards(transform.forward,posDir,moveDist,0.0f);
             transform.position = Vector3.MoveTowards (transform.position, AINodePoints [curIndex].transform.position,moveDist);
             transform.rotation = Quaternion.LookRotation(rotDir);
             if(transform.position == AINodePoints[curIndex].transform.position)
             {
                 curIndex = 1;
             }
             if(transform.position == AINodePoints[curIndex].transform.position)
             {
                 curIndex = 0;
             }
             Debug.DrawRay(transform.position, rotDir, Color.red);
             RaycastHit enemySight;
             if (Physics.Raycast (transform.position, Vector3.back,out enemySight,500.0f))
             {
                 string sightTag = enemySight.transform.tag;
                 if(sightTag == "Player")
                 {
                     transform.position = Vector3.MoveTowards (transform.position, Player.transform.position,moveDist);
                 }
             }
     
         } 
     
     
     }
 
 
 
 

But this doesn't?

  void Update () 
         {
             moveDist = speed * Time.deltaTime;
     
             RaycastHit enemySight;
             if (Physics.Raycast (transform.position, Vector3.back,out enemySight,500.0f))
             {
                 string sightTag = enemySight.transform.tag;
                 if(sightTag == "Player")
                 {
                     transform.position = Vector3.MoveTowards (transform.position, Player.transform.position,moveDist);
                 }
                 else if(sightTag == "Node")
                 {
                     Debug.Log("Running around");
                     Vector3 posDir = AINodePoints [curIndex].transform.position - transform.position;
                     Vector3 rotDir = Vector3.RotateTowards(transform.forward,posDir,moveDist,0.0f);
                     transform.position = Vector3.MoveTowards (transform.position, AINodePoints [curIndex].transform.position,moveDist);
                     transform.rotation = Quaternion.LookRotation(rotDir);
                     if(transform.position == AINodePoints[curIndex].transform.position)
                     {
                         curIndex = 1;
                     }
                     if(transform.position == AINodePoints[curIndex].transform.position)
                     {
                         curIndex = 0;
                     }
                     Debug.DrawRay(transform.position, rotDir, Color.red);
     
                 }
     
             } 
     
     
         }
     }
     
     
 
 
Comment
Add comment · Show 5
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 RaulG · Nov 13, 2014 at 05:04 AM 0
Share

I do have two objects with the tag "Node" but it seems to just freeze up ins$$anonymous$$d of continuing on.

avatar image AlwaysSunny · Nov 13, 2014 at 05:13 AM 0
Share

When possible, please post only the snippets which are relevant - nobody wants to proofread 120 lines for free. ;)

Please state the line or lines which you want proofread so we can easily locate your issue.

avatar image RaulG · Nov 13, 2014 at 05:14 AM 0
Share

Just the Update really, these things tend to go faster the more info you get.

Alright snipped out half of it.

avatar image AlwaysSunny · Nov 13, 2014 at 06:39 AM 0
Share

This is still a lot to proof without knowing more about what you're trying to achieve. A description of what is happening versus what you expect to happen is always helpful. In what way does the latter script not work? What behavior do you expect versus what behavior is observed? Can you insert some Debug.Log statements to help yourself deter$$anonymous$$e where the issue is?

avatar image RaulG · Nov 13, 2014 at 07:03 PM 0
Share

The first script has the enemy object returning to two points on the list. If the player comes into sight of the Raycast, the enemy moves towards the player ins$$anonymous$$d. If the player gets out of sight, the enemy returns to patrolling.

What happens on the second one, the enemy doesn't patrol or go after the player when it comes into sight.

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.

Follow this Question

Answers Answers and Comments

27 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

FIXED: How can I stop a collider from tunneling? 2 Answers

Void Execution Question 0 Answers

Balancing Forces + Gravity 1 Answer

Finding the axis of a curving pipe 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