[Closed] distance from a moving object
I want to create keyframe for objects depending of their distance from a moving object.
Need help!
try to explain better what you want to do…
do you have a set of static objects and do you want to create a key for any object of this set depending of the distance between this object and some moving object not from this set? What kind of key (type of controller) do you need to create?
Ok, imagine many objects in a scene, then a SphereDummy moving trough the scene. When object is in the sphere radius a keyframe is created in visibility then another 15 frame later with a new visibility value. Basically the SphereDummy contact with object make them appear.
I just can’t find a good basis for detecting distance along the time…
I am learning So I need some help. Thank you.
here is my very start:
for o in objects do
(o.visibility = bezier_float()with animate on
(–rndm = random 0 10
fr1 =
duration = 15
at time (fr1) o.visibility.controller.value = 0 at time (fr1+duration) o.visibility.controller.value = 1 ) )
do you want to generate keys in real time or you want to create and bake keys using existent animation of some object?
in the first case you have to use some moving callback to check a current distances like:
when transform moving_obj changes handleAt:#timeChange do
(
at time currenttime with animate on with undo off
(
for obj in static_list where (d = distance obj moving_obj) < something do
obj.visibility = <whatevere you want>
)
)
it’s better to organize it as a function and define an ID for this change handler
second case:
define the time interval for baking and time step…
lets say interval is (interval 0 100f) and step is 1 frame
for f=0 to 100 do at time f
(
for obj in static_list where (d = distance obj moving_obj) < something do
with animate on obj.visibility = <whatevere you want>
)
i can’t check the code, so use this as an idea…
… of course if you want to make kinda “fade in – fade out” effect you have to check the distance for less and more, and create keys for both conditions if it’s necessary.
oops… my bad…
of course it must be obj.visibility = … — (not obj.visible)
interested in second case… but i m lost!!
this doesn’t work
for o in objects where (d = distance o $SphereGizmo01) < 50 do
(with animate on
(
for f=0 to 50 do at time f o.visibility.controller.value = 0 for f=0 to 50 do at time f+ 15 o.visibility.controller.value = 1 ) )
lets define the task more exactly…
- we have a list of static objects and one moving object
- every object from the list has bezier float type of visibility controller
- if the distance between some object from the list and the moving object becomes less then something it sets visibility of the object to 0 (step key)
- any object from the list can’t stay invisible longer then 15 frames (or has to stay invisible during 15 frames).
am i right?
ok… we have to bake visibility animation based on the moving object animation on current animation range interval…
- apply bezier float controller to visibility track of every object of the list
for obj in list do
(
obj.visibility.track = bezier_float()
deletekeys obj.visibility.track #allkeys
obj.visibility = 1.0 – make visible by default
) - create pair of visibility keys (hide/unhide) for objects which are closer then something to the moving object
for t=animationrange.start to animationrange.end do at time t
for obj in list where (d = distance obj moving_obj) < something do
(
– check if visibility of this obj is not already animated (skip if it’s already hidden)
if obj.visibility >= 1.0 do
(
– hide
k0 = addnewkey obj.visibility.track t
k0.value = 0.0
k0.inTangentType = k0.outTangentType = #step
– unhide 15 frames later
k1 = addnewkey obj.visibility.track (t+15f)
k1.value = 1.0
k1.inTangentType = k1.outTangentType = #step
)
)
thank you DenisT…
what does that mean?
k0.inTangentType = k0.outTangentType = #step
it means the key’s in and out tangent types are #step. The controller works like BOOLEAN (true or false). 1.0 == true, 0.0 == false… There is no interpolation between keys.
check bezier controller keys reference in MXS help for details…
thank you man, I m learning many things tonight
I will dig the way you tell me…
if you want to get smooth transition from 0. to 1. (fade in) set #smooth type for OUT of key at time t and for IN and OUT for key (t+15f)