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 Jordan 7 · Dec 04, 2010 at 11:48 PM · javascriptmovementaienemy

AI controller script, Enemy movement issues

I'm new here, so bear with me.

Essentially the issue is that the "enemy" right now, just a cube, is moving towards the character as it should, however, it doesn't recognize when to stop moving towards the character. When I used the print function to debug, the only messages that showed up are "too close", and "in range". These messages were constantly active. No matter what I tried, the cube just moves towards the character, and when it hits the character, it initially will nudge at the character, but when the character moves, it proceeds to go inside the character, constantly nudging, and shaking, sometimes throwing it across the map.

I have set up a boolean setup, as shown, to make sure it is formatted cleanly and debugging is made easier. Here is the script:

var sightRange = 75.0; var idealRange = 5; var speed = 15; var startAttackrange = 15; var spacebtwn = Vector3.Distance(transform.position, player.transform.position); var player = GameObject.FindWithTag("Player"); var delayTime = 0.0; var backspeed = 10; var rateofFire = .75; var initialSpeed = 30; var projectile : Rigidbody;

function TooClose() { if(spacebtwn < idealRange) { print("tooclose"); return true; } else return false; }

function InRange() { if(spacebtwn <= sightRange) { print("In range"); return true; }

 if(TooClose == true)
 {
     print("inrange is false");
     return false;
 }

 if(spacebtwn &gt; sightRange)
 {
     print("out of range");
     return false;
 }

}

function AttackRange() { if(spacebtwn >= idealRange && spacebtwn < sightRange) { return true; } else return false; }

function Update() { if(InRange() == true) { var direction = player.transform.position - transform.position; transform.Translate(Vector3(0, 0, 1) speed Time.deltaTime); transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(direction), Time.time); }

 if(TooClose() == true)
 {
     transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(direction),  Time.time);
 }

 if(AttackRange() == true)
 {
     print("attacking");
     Attk();
 }

}

function Attk () { if (Time.time > rateofFire) { // create a new projectile, use the same position and rotation as the Launcher. var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);

         // Give it an initial forward velocity. The direction is along the z-axis of the missile launcher's transform.
         instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0, 0, initialSpeed));

         // Ignore collisions between the missile and the character controller
         Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);

         lastShot = Time.time;
     }
 }

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 Justin Warner · Dec 05, 2010 at 12:01 AM 0
Share

Just some scripting tips... Use whole words for your scripts... And don't put cuss words in... $$anonymous$$aybe add some comments too...

avatar image Jordan 7 · Dec 06, 2010 at 12:40 AM 0
Share

I am so sorry that was left in there it was a joke between me and my friend as we got frustrated trying to fix this. I just edited it out. To anyone who read this script before I did edit it out I am so sorry and thank you for viewing and trying to help.

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

No one has followed this question yet.

Related Questions

Enemy AI With changing Player 0 Answers

Enemy controller.move script slows down and speeds up. How to get it consistent? 0 Answers

2D sidescroller ranged character shooting problem. 0 Answers

Enemy following Player on uneven surface 1 Answer

2D Random AI 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