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 abi-kr01 · Jun 25, 2014 at 12:52 PM · 2dmovementai

aquarium effect for 2d fish

i want simple 2d Ai for my fish ,with little R&D i figure out different type of solution but i dont think that is applied to my case

 solution that i found was 
 

    1)use of way points(but it my fish will use the same path over and over again  which is not god if you have 100 fish and all use one update function each to follow way points 
     2)use of trigger![alt text][1]


[1]: /storage/temp/28259-triger.png

but here also i can only move my object to same point left to rit

but i want effect like aquarium

triger.png (3.4 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by HappyMoo · Jun 26, 2014 at 12:13 AM

Just pick a random target point within the aquarium and use Vector3.MoveTowards with the fish speed to move him towards that point. When he reached it, pick a new target.

For smoother movement, don't move the actual fish with MoveTowards, but another target and Lerp or MoveTowards the fish to this target. In summary: Pick end target. Move current target with MoveTowards till it reached end target, then pick a new end target. Lerp/MoveTowards tthe fish position between current position and current target. This is similar to what musranya is saying, but produces more even speeds, so the fish isn't rushing at the start and get slower later and also produces rounded paths like bezier curves and not just linear segments.

If you wanna go more complex, google swarming and flocking behaviour. You'll probably also find some unity implementations.

Let me know if you have more questions about implementing this solution.

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 abi-kr01 · Jun 26, 2014 at 01:55 PM 0
Share

Happy $$anonymous$$oo , using move towards cause alt text

have.png (3.1 kB)
avatar image abi-kr01 · Jun 26, 2014 at 01:56 PM 0
Share

which should be ,fish face will be facing way point. how can i do that ?

avatar image HappyMoo · Jun 26, 2014 at 03:07 PM 0
Share

$$anonymous$$oving and facing direction are to separate things. I told you how to move. Apart from that, after you calculated which direction you have to move, you can update your rotation... something like this:

 fish.transform.rotation = Quaternion.LookRotation(moveDirection, Vector3.up);
avatar image HappyMoo · Jun 28, 2014 at 07:55 AM 0
Share

Did that help? Please accept the answer if so.

avatar image
0

Answer by musaranya · Jun 25, 2014 at 01:43 PM

A possible approach would be to create various sets of waypoints (or paths) and then assign the path to each fish randomly. Also you can introduce params when assigning a path to a fish, p.e. variable Lerp velocity between points, an initial position offset, etc.

Another idea taht needs to be tried in order to now if it makes de trick: set points at the corners of the tank and, for the movement of the fish, make a lerp from its initial position to one of these points randomly. After a few secs, change the target point of the Lerp randomly again, and so one. If it works you should have a bunch of fishes swimming around the tank and never reaching the corners

Well, are just a few ideas, anyway hope you can make it :)

Comment
Add comment · Show 1 · 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 abi-kr01 · Jun 26, 2014 at 01:41 PM 0
Share

Thanks musaranya

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

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help with 2D AI scripting 2 Answers

2D Platformer Ai Movement Decision Making Problems 0 Answers

Simple AI In 2D - C# 1 Answer

enemy AI patrol not working 1 Answer

moving AI up/down if lower/higher in Sector as player 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