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 Ruffy789 · Aug 25, 2012 at 04:20 AM · follownotworking

Following Script Not Working Properly

Hey guys, i have a problem with my script here, the script works but when the enemy follows me it keeps descending with as result going trough the terrain (putting the model higher doesn't work) other then that the script works perfectly fine. Thanks in advance.

The Script:

 #pragma strict
 
 function Start () {
 
 }
 
 //target to follow 
 var target : Transform;
 
 //Checks his position
 var pos : Transform;
 
 //Ray variables
 var rayLength : float = 3;
 
 //Speed
 var speed : float = 4;
 
 //Move
  var move : boolean = false;
 
 function FixedUpdate() {
 
 }
 
 function Update() {
 var fwd = transform.TransformDirection (Vector3.forward); var hit : RaycastHit;
 
 
     if (renderer.isVisible)
     {
     move = false;
     }
 
  
     if(!renderer.isVisible)
     {
     move = true;
     }
 
     //Follows meh i don't watch him
     if(move)
     {
     //Look at target
     transform.LookAt(target);
     //Follow meh
     pos.position += pos.forward * speed * Time.deltaTime;
     }
 
     //Temp avoidance
     if (Physics.Raycast (transform.position, fwd,rayLength)
 && move)
     {
     Debug.Log("Moving.");
     transform.Translate(Vector3.right * 3 * Time.deltaTime);
     }
 
 }
Comment
Add comment · Show 3
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 Sequence · Aug 25, 2012 at 04:33 AM 0
Share

So, when it's following you, it goes in your direction but keeps moving down slightly?

avatar image Ruffy789 · Aug 25, 2012 at 04:36 AM 0
Share

Yes, exactly as you said.

avatar image Ruffy789 · Aug 25, 2012 at 01:27 PM 0
Share

I was able to fix the sinking, but now he does the same thing in the air. (He flies)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Ruffy789 · Aug 25, 2012 at 02:16 PM

I think i fixed it by adding a Box collider with Rigidbody and enabling gravity. There are no worries now as in the game he won't be going over steep things.

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Script working on some objects but not others 1 Answer

Pickup script not workimg 0 Answers

Can't get bullet to spawn and move 1 Answer

Door script not working when door is turned 90 degrees 1 Answer

Walking script not working need help 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