Activity › Forums › Adobe After Effects Expressions › Move Null to location based on slider
-
Move Null to location based on slider
Posted by Lukasz Pason on January 22, 2015 at 12:57 amI want a slider to control the position of a null based off the coordinates of other layers. Now, I think I have the base structure of the expression but I may be a long way off as wel…. Help if you can.
Cont1 = Cont1Mark[0,1];
Cont2 = Cont2Mark[0,1];
Cont3 = Cont3Mark[0,1];
Cont4 = Cont4Mark[0,1];
Cont5 = Cont5Mark[0,1];
Cont6 = Cont6Mark[0,1];
ContSel = SliderControl valueif { ContSel = (1)
value = Cont1
}
else {
[0,1]
}
if { ContSel = (2)
value = Cont2
}
else {
[0,1]
}if { ContSel = (3)
value = Cont3
}
else {
[0,1]
}if { ContSel = (4)
value = Cont4
}
else {
[0,1]
}if { ContSel = (5)
value = Cont5
}
else {
[0,1]
}if { ContSel = (6)
value = Cont6
}
else {
[0,1]
}
Motion Designer / DJ / Father
http://www.lukaszpason.com
http://www.krop.com/lukaszLukasz Pason replied 11 years, 3 months ago 3 Members · 12 Replies -
12 Replies
-
Dan Ebberts
January 22, 2015 at 1:26 amThat seems like a lot of code for whatever you’re doing. What is in the array Cont1Mark ?
Dan
-
Lukasz Pason
January 22, 2015 at 1:33 amHere’s what I finally came up with but the null I want to move to those positions isn’t actually moving. Also, Having it actually slide instead of jumping to positions would be ideal.
Cont1 = thisComp.layer(“Cont01”).transform.position;
Cont2 = thisComp.layer(“Cont02”).transform.position;
Cont3 = thisComp.layer(“Cont03”).transform.position;
Cont4 = thisComp.layer(“Cont04”).transform.position;
Cont5 = thisComp.layer(“Cont05”).transform.position;
Cont6 = thisComp.layer(“Cont06”).transform.position;
ContSel = thisComp.layer(“AUTO SCRIPT CONTROLLER – CONTINENT”).effect(“Slider Control”)(“Slider”);if (ContSel = (1)){
value = Cont1
}
else {
[960,540]
}if (ContSel = (2)){
value = Cont2
}
else {
[960,540]
}
if (ContSel = (3)){
value = Cont3
}
else {
[960,540]
}
if (ContSel = (4)){
value = Cont4
}
else {
[960,540]
}
if (ContSel = (5)){
value = Cont5
}
else {
[960,540]
}
if (ContSel = (6)){
value = Cont6
}
else {
[960,540]
}Motion Designer / DJ / Father
http://www.lukaszpason.com
http://www.krop.com/lukasz -
Dan Ebberts
January 22, 2015 at 2:43 amYou need to string those else clauses together like this:
if (ContSel == (1)){
value = Cont1
}else if (ContSel == (2)){
value = Cont2
.
.
.
}else{
[960,540]
}
but I think I’d do it this way:
ContNames = ["Cont1","Cont2","Cont3","Cont4","Cont5","Cont6",];
ContSel = thisComp.layer("AUTO SCRIPT CONTROLLER - CONTINENT").effect("Slider Control")("Slider");
try{
thisComp.layer(ContNames[Math.round(ContSel)-1]).transform.position;
}catch(err){
[960,540]
}Dan
-
Lukasz Pason
January 22, 2015 at 4:07 amI was cycling home and thought of that exact thing, I need to set up a string! Nice to see that my coding is starting to get better. No comparison but it feels good.
Your solution, I didn’t know you could set up a series of names in a variable! Great piece of info to know. I’m not familiar with the ‘try’ though… Is it literally just saying to try and use what the input from the slider is? That’s pretty cool if it is.
Last question for you. Is there a way to modify this so that the null actually slides into position with ease?
-
Dan Ebberts
January 22, 2015 at 5:08 am>I’m not familiar with the ‘try’ though… Is it literally just saying to try and use what the input from the slider is?
The try/catch construct is to keep the expression from breaking if the value of the slider goes negative or becomes larger than the size of the name array.
>Is there a way to modify this so that the null actually slides into position with ease?
From where? The previous position? Possible, but not simple and very dependent on how you set things up.
Dan
-
Lukasz Pason
January 22, 2015 at 5:23 amThanks for the info and help Dan! I didn’t think it would be easy to make the null move from spot to spot rather than just jump to it. Maybe another day. =)
Motion Designer / DJ / Father
http://www.lukaszpason.com
http://www.krop.com/lukasz -
Dan Ebberts
January 22, 2015 at 5:29 amThe expression would need to be able to figure out the previous and next values of the slider. If you have the slider controlled by keyframes it would be fairly straightforward, but there would be a bit of code involved.
Dan
-
Lukasz Pason
January 23, 2015 at 5:42 pmI am actually key framing the slider in this instance. I do have a question, there seems to be a frame of lag, is that something that is intentional in the code?
Motion Designer / DJ / Father
http://www.lukaszpason.com
http://www.krop.com/lukasz -
Lukasz Pason
January 23, 2015 at 5:55 pmThe one you had suggested. =)
ContNames = ["Cont1","Cont2","Cont3","Cont4","Cont5","Cont6",];
ContSel = thisComp.layer("AUTO SCRIPT CONTROLLER - CONTINENT").effect("Slider Control")("Slider");
try{
thisComp.layer(ContNames[Math.round(ContSel)-1]).transform.position;
}catch(err){
[960,540]
}
Motion Designer / DJ / Father
http://www.lukaszpason.com
http://www.krop.com/lukasz
Reply to this Discussion! Login or Sign Up
