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 Michael 16 · May 03, 2011 at 03:43 PM · aidistanceattack

Too Close To The Trap and melee attacking enemys.

I created an enemy that attacks when i get close to him. When I get close, it should coming out a bit from the water and attack me. The problem it that it don't works untill I get too much close to him, I meen that insted of it will start to attack me from 10 meters range, it attacks me from 1 meter range or less. I tried with 500 meters and it still doesn't works. How do I solve the problem?

Here is my script if something wrong there:

var distance; var target : Transform; var speed = 4.0; var landDistance; var land : Transform; var attackRange = 10.0; var floteRange = 2.0; var goUp = false; static var FIRE = false;

function Update () { distance = Vector3.Distance(target.position, transform.position); landDistance = Vector3.Distance(land.position, transform.position);

  if (distance < attackRange)
  {
      goUp = true;
  }
  else
  {
      FIRE = false;
  }

  if (goUp)
  {
      if (landDistance <= floteRange)
      {
          transform.Translate(Vector3.up * speed * Time.deltaTime);
      }
      else
      {
          FIRE = true;
      }
  }

}

One more thing that i want to know is to create melee attack enemy. I don't know how to start, from where or anything else... Someone can tell me how to begin or the basics? It not something importent, it just can be fun to do...

Sorry for poor english...

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

1 Reply

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

Answer by GesterX · May 03, 2011 at 04:00 PM

Your code looks fine.

Make sure that you are changing the value of attackRange in the inspector and not in the script. For some reason I have found that once the script is attached to the object - changing the values in the script do not change the values for the object. You need to change them in the object inspector itself.

Comment
Add comment · Show 4 · 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 Michael 16 · May 03, 2011 at 04:36 PM 0
Share

It not really the problem... I did changed the theme in the object inspector. But I solved the problem like that: 10 meters is not enough!!! It too close to him, now it 40 meters and it's enough. 10 meters looks like 1 meter in my game...

avatar image GesterX · May 03, 2011 at 06:02 PM 0
Share

Okay. You should note that the "distances" in Unity are not in "meters" they are just a representation of the co-ordinate system.

avatar image Owen-Reynolds · May 03, 2011 at 11:46 PM 0
Share

So 500 meters did nothing? But now 40 meters does? floteRange is a little odd -- it says the monster has to stay within a circle to attack.

avatar image Michael 16 · May 04, 2011 at 02:13 PM 0
Share

$$anonymous$$eters, not meters; 500 meters, 40 meters; the problem solved... Thats it... No more questions here...

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

How to make AI enemy do damage and only attack inside a distance or range 2 Answers

Adding Distance in javascript 2 Answers

Ai Zombie Melee Attack script. 5 Answers

Enemy behavior is not working after the enemy has spawned. 1 Answer

Make Navmesh agent follow closest object with tag 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