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
2
Question by user-3061 (yahoo) · Nov 20, 2010 at 10:27 AM · fpsaidamagerangehealth

Ai that applies damage when in range?

Hi, I'm making a FPS based from the FPS tutorial and has made a basic ai that follows me and maintains a constant distance between it and the character. Does anyone has an idea on how to make the Ai apply damage over time if it is in range with the player? I'm a total noob on scripting and just need a rough guideline to continue it...thanks!

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
1
Best Answer

Answer by Bravini · Nov 20, 2010 at 12:54 PM

the best way IMO : you gonna need a trigger that will be attached on your enemy. Use the OnTriggerStay function, if statement the object in it have the tag "Player", (set your player object to have that tag) if it does, use SendMessage to call a damage function in your player(this damage function can be found in scripts like CharacterDamage in the FPS tutorial). Now you have it sending the damage. All you gotta do then is limit how often the if statement should be read (example on the rocket launcher script in the FPS tutorial for this). that is, make 2 float variables, one called dmgFrequency and another called hitTime. your if statement gonna end like this

if(col.gameObject.tag ==("player") && hitTime+dmgFrequency < Time.time){

 <blockquote>
   <p>col.SendMessage("ApplyDamage", 1);</p>
   
   <p>hitTime= Time.time;</p>
 </blockquote>
 
 <p>}</p>

being col the variable that is in contact with the trigger.

http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=trigger

Comment
Add comment · Show 3 · 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 user-3061 (yahoo) · Nov 21, 2010 at 02:46 AM 0
Share

so now i need to make the enemy actually collide with my player? I'm actually preventing his, because im making an FPS, so if the enemy collides to the player, it would be too close to the camera.that's why i maintained a distance between the player and the enemy. What i mean is that I need a script that can apply damage from a small range, without colliding to the player. Is there any way to some kind o fake collider that just senses the player if its in range, and apply damage from time? thanks for the answer!

avatar image Bravini · Nov 21, 2010 at 10:14 PM 0
Share

triggers are exactly that, they don't react phisycally, so the objects go through them, think of it as a zone. You can set a trigger scale as you wish too.

avatar image user-3061 (yahoo) · Nov 22, 2010 at 01:38 AM 0
Share

ok, il try that, thanks!

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

Deal damage on collision 2 Answers

Health and damage reciever 1 Answer

Looking for skilled individual to assist with problem 1 Answer

The enemy don´t lose health, but why??? 0 Answers

Ai that applies damage in collision? 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