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 /
This question was closed Mar 11, 2017 at 12:33 PM by itsharshdeep for the following reason:

Here, no one is pretty much available for the detailed task.

avatar image
0
Question by itsharshdeep · Mar 10, 2017 at 08:10 AM · vector3directionmaths

Need help for direction calculation.

Hi

I need help regarding a question related to maths/vector. Attached scripts contain the flocking algorithm. All the flocks follow the target/goal (as shown in the below image). Everything is working fine when the placement of the manager script is at position 0,0,0 x,y,z coordinates. But I don’t them to be placed at vector3.zero.

So, I want the help for editing the script. I want as I can place the manager at anywhere in the World and result should be same.

Following is the reference from where I got the source code/tutorial: https://www.youtube.com/watch?v=eMpI1eCsIyM

Source files: http://files.holistic3d.com/yt/eMpI1eCsIyM.zip

Pastebin code for the same scripts:

flock.cs: http://pastebin.com/2nAWvdK8

globalFlock.cs: http://pastebin.com/LMUzfEdM

I just edited the source files just to make all the fishes child of the parent: https://www.dropbox.com/s/9xo3olv0x8dxfj4/FishesUpdated.unitypackage?dl=0

P.S. I think the issue is in the flock.cs there is a line just after the if(turning) which is calculating the direction:

 Vector3 direction = Vector3.zero - transform.position;


Please help me out.

Thanks,

Harshdeep

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

  • Sort: 
avatar image
0

Answer by Lylek · Mar 10, 2017 at 11:03 AM

Hey there, I took a look at the video (not all of it) and it looks like Vector3.zero is used quite often to reference the 'center' of the 'tank'. That is very unfortunate! :(

I would create a new Vector3 variable (or not even, if FishManager is the center of the 'tank', and never moves, you can just reference its transform.position) and go through the globalFlock script changing Vector3.zero to transform.position, where appropriate. And the Flock script will require a reference to the FileManager's position. You can either create a variable for this in the flock script and assign it, directly after instantiate, like:

             allFish[i].GetComponent<Flock>().yourVector3Variable = transform.position;

Or, it looks like parenting the fish to the FileManager might be a good idea, and after instantiated, write:

             allFish[i].transform.parent = transform;

Then you can reference the FishManager's position, or the center of the 'tank', by using, transform.parent.transform.position, in the Flock script.

The last issue I saw is the random spawning of the fish, from the globalFlock script. The Vector3 variable "pos" is generated by negative and positive values of "tankSize", which would only give a position around Vector3.zero. I think you can fix this one easily though, by adding "+ transform.position" when the fish is instantiated, like:

             Instantiated(fishPrefab, pos + transform.position, Quaternion.identity);

This should add the position of the FishManager into account.

Again, I didn't watch the entire video, so I hope this is accurate enough. ;) Best of luck!

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 itsharshdeep · Mar 10, 2017 at 03:35 PM 0
Share

Hi @Lylek23 :

Thanks a lot for the reply. I agree on your all above stated points, but I have already done all the steps, but hard luck :(

However, regarding your second point. I have made the fishes child of the parent so they instantiated under them.. but I will again review that part. Thanks for second issue.

Follow this Question

Answers Answers and Comments

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

Related Questions

Setting up point sets for a procedural tree 1 Answer

Get rotation from a vector direction. 1 Answer

a variable that allows you to choose either x,y, or z? 3 Answers

Plane geometry 0 Answers

Fire Knockback 3 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