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 /
This question was closed Sep 24, 2013 at 09:35 AM by Fattie for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by Kwayzie · Sep 24, 2013 at 01:01 AM · raycastenemychase

can someone look at this script for me

i need help finding out whats wrong with this. it gives me no error and i can play but once my enemy shows up, it gives me a error. i want him to show up and not move until my flashlights points on him. so im trying to create a raycast to hit the flashlight and when it i want the enemy to chase me, if that makes sense

 var Player : Transform;
 var moveSpeed = 1;
 var maxDist = 5;
 var minDist = 1;
 var length = 30;
 
 function Update()
 {
     var hit : RaycastHit;
     var ray : Ray = Transform.Position(Vector3.forward);
     
     transform.LookAt(Player);
     
     if(Physics.Raycast(ray, hit, length))
     {
         if(hit.collider.tag == "FlashLight")
         {
             if(Vector3.Distance(transform.position, Player.position) >= minDist)
             {
                 transform.position += transform.forward*moveSpeed*Time.deltaTime;
             }
         }
     }
 }
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 Tim-A · Sep 24, 2013 at 01:07 AM 0
Share

What is the error?

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Sep 24, 2013 at 01:13 AM

Issues like this one are a good reason why you should always use '#pragma strict' at the top of your files. With the pragma you would have received a compile-time error and would have seen the problem. I suggest you change to a different form of Raycast. Try this:

 var Player : Transform;
 var moveSpeed = 1;
 var maxDist = 5;
 var minDist = 1;
 var length = 30;
  
 function Update()
 {
     var hit : RaycastHit;
  
     transform.LookAt(Player);
  
     if(Physics.Raycast(transform.position, transform.forward, hit, length))
     {
        if(hit.collider.tag == "FlashLight")
        {
          if(Vector3.Distance(transform.position, Player.position) >= minDist)
          {
           transform.position += transform.forward*moveSpeed*Time.deltaTime;
          }
        }
     }
 }
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 Kwayzie · Sep 24, 2013 at 01:36 AM 0
Share

that works perfect, thanks....i still dont know what was wrong with $$anonymous$$e tho...i fail at at creating scripts :(

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Multiple Cars not working 1 Answer

Enemy Health With Raycast Not Working 1 Answer

Enemy raycast chase player 0 Answers

How to Stop Enemy "Shooting Through A Wall" 1 Answer

Follow Nearest Target 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