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 VAN-D00M · Jul 21, 2014 at 05:39 PM · collisionavoidance

AI Bouncing off Boundaries & Avoiding Other AI

Hi

I've got two different AI's in my top down shooter which I both want to make better.

  1. Floating Hazards - hit and ricochet off of the invisible boundary's

  2. Enemies - Needs to avoid colliding with each other

I have an Invisible boundary set up for the player and the Hazards. Enemies just follow the player but are libel to collide with each other.

Hazards: The hazards currently have Random.range controlling their movement direction which seems to work. If they were hitting a boundary that wasn't invisible I would probably look at an 'OnTriggerEnter (Collider other)' and loop the random.range when the hazard hit the boundary. But with it being invisible I don't quite know what to use instead?

Enemies: I would have liked these to move around following the player and avoiding each other. I see multiple ways of doing this but unsure of the best way. I see a lot of things about having 2 colliders and ray casts which make sense to me but unsure how to implement those.

Neither of these are major and have seen information all over the place but I'm just unsure of the best way and how to implement. I'm not a total noob to programming but I'm no where near fluent.

Any help offered would greatly appreciated. Cheers :)

EDIT for the hazard I have tried putting the boundary positions into a variable and having that in an if statement but that didn't work and I tried a couple of other ways but the way i'm doing it is probable wrong. I can't be far off. This is the code I've been working with. I may be approaching this all wrong, don't be afraid to say I'm totally wrong.

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class HazardBoundary
 {
     public float xMin, xMax, zMin, zMax;    
 }
 
 
 public class AsteroidMover : MonoBehaviour 
 {
     public float speed;
     public float tumble;    
     public HazardBoundary boundary;
 
  
     void Start ()
     {
         Vector3 randomDirection = new Vector3(Random.Range(-1, 2), 0.0f, Random.Range(-1, 2));
         rigidbody.velocity = randomDirection * speed;
     }
 
 
     void Update()
     {
         //boundary
         rigidbody.position = new Vector3 
             (
                 Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax), 
                 0.0f,
                 Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
                 
             );
 
         //been trying to recall the code in the start with an if statement
         if ()
         {
             Vector3 randomDirection = new Vector3(Random.Range(-1, 2), 0.0f, Random.Range(-1, 2));
             rigidbody.velocity = randomDirection * speed;
         }
     }
 
 
 
 }
 




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

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

2 People are following this question.

avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Scene Change Collision 2 Answers

Troubleshoot C# collision trigger 0 Answers

Fist Passing Through The Target 2 Answers

Basic Collision, Object + First Person 2 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