Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 felipeRDS · Aug 19, 2016 at 01:23 PM · enemyprefabsshot

How to make an enemy to deviate from shots?

I want to make an IA of my game . I need a way to get the shots (prefabs) in the game to compare with the enemy , and the enemy to deviate .

I've already tryed to put the prefabs in the variables on script but it didn't work. I want to get the shots and compare with the enemy position .

How can I do it?

Please I'm beginner on unity.

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

3 Replies

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

Answer by dr_adrii · Aug 20, 2016 at 09:43 AM

There are simple steering behaviour AI methods that you can find that will allow the unit to automatically try to avoid other objects without needing user input. This link looks at collision avoidance, but you can combine them to give more flexibility :

http://gamedevelopment.tutsplus.com/tutorials/understanding-steering-behaviors-collision-avoidance--gamedev-7777

Combine this with functionality such as Ray cast to track the enemy projectile wrt your position, and it will try to adjust it for avoidance. You can also place a radius of movement around your unit to stop it going too far. There is a good book called The Nature Of Code by Daniel Shiffman, which explains them all very well.

Note these are very simple compared to technology we see these days, but I guess you should aim for a solution that is as simple as your needs require.

Hope it helps

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
avatar image
0

Answer by thor348k · Aug 19, 2016 at 06:34 PM

By your explanation, do you mean you want the enemy to strafe away from incoming shots (bullets)? If so, are the enemies facing the player? Or wherever the shots are coming from?

If so, then you can do a raycast from the enemy, to the player. If there's a collider hit for a bullet, then strafe the enemy. You can also do a check for distance on the incoming bullet, if the bullet is say, less than 1 unit away, strafe. Otherwise, don't

Raycast: https://docs.unity3d.com/ScriptReference/Physics2D.Raycast.html Distance: https://docs.unity3d.com/ScriptReference/Vector2.Distance.html

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
avatar image
0

Answer by felipeRDS · Sep 01, 2016 at 08:35 AM

alt text

I've seen about ray and raycast and I got make the shoots to fire a ray.

Well, my game is this way. I'm using ray when the shots have created. Now I want that the enemy( red nave) catch these rays to move to any side.

Do I need do the verification on the same script of the shots? Because on the enemys's script I'm going to need catch the rays, but not when the game has started.

Is my idea correct? What is the best way to do it? I'm so beginner.


forum2.png (206.6 kB)
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 2d count collisions ontriggerenter? 1 Answer

How to get the position of a new Instantiated prefab 1 Answer

How to check where I'm being shot from. 1 Answer

help with if(hit.gameObject.tag) 0 Answers

Multiple Doors and Buttons 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