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
3
Question by runevision · Jan 21, 2010 at 11:05 AM · physicsvectorflow

Move an object according to a vector field (flow arrows placed in the scene)

I have an object that I want to get moved in a direction that is controlled by flow arrows placed in the scene. The arrows could just be game objects that push in their Z direction by an amount corresponding to their Z scale.

This could be used for moving an object floating in a water stream, an air stream, or for defining weird custom gravity.

Maybe the object should be moved by only the arrow that is closest at any given time, or maybe by a blend (interpolation) of the closest arrows around the object.

A) How do I efficiently find the one closest arrow?

B) How do I efficiently find the closest arrows around the object (neighbors) and interpolate between their directions such the the closest ones have most effect?

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

Answer by runevision · Jan 21, 2010 at 11:32 AM

The problem is really two different issues:

1) Find the closest arrows efficiently.
2) (Only needed for B) Interpolate between the closest arrows.

You have solve 1) in a number of different ways.

  • If you only have a small number of arrows in the scene (say, less than 30) it may be fastest to just store them all in a list, and iterate through them all to find the closest.

  • If you know there will never be more than X units between arrows, you can use a collider with radius X to find the arrows within that radius. You can then iterate through those and find the closest one(s).

  • If you have many arrows and they are placed close together in some places and far apart in other places, the above methods may not work efficiently. You can try instead to give all the arrows colliders and make sure the colliders overlap. This lets you use small colliders where the arrows are packed closely and large colliders where they are far apart. You then know in each frame which arrow colliders your object is inside.

  • Another option is to do some pre-processing at design time to make computations more efficient at runtime. You could have a 3d array of Vector3s that divides your game space into "cells". You can make an editor script that calculates the appropriate flow vector for each of the cells, based on one of the above methods. At runtime you then don't need to use the actual arrows - instead you can make a cheap look-up in the array to find the flow vector for the cell your object is currently in. You can also use trilinear interpolation to interpolate the flow vector smoothly.

There are more ways this can be done, but the above should provide a good starting point.

As for solving issue 2), that is a problem of multivariate interpolation in a non-uniform grid.

  • A simple interpolation method is Inverse Distance Weighting, which weights the data points (arrow vectors in this case) according to the inverse of the distance to them.

There are many other methods. Look for research in "Scattered Data Interpolation" to learn more.

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 panta · Feb 14, 2013 at 02:42 PM 0
Share

Thanks, Rune. I'm looking to do a similar gravity vector field and your comments are very helpful.

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

1 Person is following this question.

avatar image

Related Questions

CharacterController on Moving Surface 4 Answers

Flowing water with a fixed volume 1 Answer

Rigidody.velocity = Direction * speed; How to get direction? 1 Answer

How to get the tangent and normal of a collision? 1 Answer

Direction of rotation and ApplyForce 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