Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Expression to make an object avoiding another one

Community Beginner ,
Nov 09, 2018 Nov 09, 2018

Hello,

I would like to automate the position of an object "A" in such a way that when an object "B" is getting closer (around 100px of distance), the object A would dodge B.

I don't know if it will be useful but here is a sketch of what I would like to do :

A→            B

----------------------

         A→   B

----------------------

               A→

                  B

----------------------

                     A→

                  B

----------------------

                   B       A→

Thanks in advance !

1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 09, 2018 Nov 09, 2018

It's going to take some modification of some or all of these techniques demonstrated and explained by expression guru Dan Ebberts:

Proximity Detection

Collision Detection

Elastic Connection

I don't have time to give you the expression but I can give you the idea.

  1. Define Layer A and B. If you want to make B move when A gets near then consider placing Layer A above Layer B and using thisComp.layer(index - 1) in the expression you add to layer B so you can paste it into any layer without renaming the la
...
Translate
Community Expert ,
Nov 09, 2018 Nov 09, 2018

I can think of ways this would be possible, but unless you're doing a ton of these, I have a feeling it's going to be more successful to animate this by hand.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 09, 2018 Nov 09, 2018

I would like to do this with aproximately 20 objects, so I don’t know wich would be the easiest way..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 09, 2018 Nov 09, 2018

What is the nature of object A's movement? simple X axis left to right as per your sketch above - or something more random?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 09, 2018 Nov 09, 2018

It's going to take some modification of some or all of these techniques demonstrated and explained by expression guru Dan Ebberts:

Proximity Detection

Collision Detection

Elastic Connection

I don't have time to give you the expression but I can give you the idea.

  1. Define Layer A and B. If you want to make B move when A gets near then consider placing Layer A above Layer B and using thisComp.layer(index - 1) in the expression you add to layer B so you can paste it into any layer without renaming the layer
  2. Decide how you want Layer B to react when Layer A gets close - consider revising he Elastic Connection code
  3. If you want all layers to react to all other layers, randomly or based on angles consider adapting the sampleImage(point, radius = [.5, .5], postEffect = true, t = time) method from the Expression Language>Layer>General menu to look outside the layer boundaries for alpha channel changes

The there option, which would work very well if you have 3D layers is Newton 3 . That would be the easiest way I know of to quickly generate collisions between layers.

There may be some other scripts out there that I don't know about. So I guess it comes down to figuring out if you have several hours to devote to figuring out how to modify Dan Ebberts' sample expressions or do you have about $250 to spend on a 3rd party solution.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 09, 2018 Nov 09, 2018

If you want the motion to be smooth, do it by hand.  If you don't care how the motion looks, code it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 09, 2018 Nov 09, 2018

For 20 layers I think Kyle and Dave's suggestion is probably the right one. You'll probably spend longer building and tweaking an expression than it would take to keyframe it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 09, 2018 Nov 09, 2018

What Dave said. Do it by hand. It's just a measly 20 layers, after all.

Mylenium

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 10, 2018 Nov 10, 2018
LATEST

Thanks a lot for all your help !

Have a good week-end.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines