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

Expression to detect horizontal axis vector

Explorer ,
Nov 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

Hey guys. I'm trying to make an object that is gonna horizontally flip itself when it changes his x axis vector.
 

It basically works, but the problem here that when object isn't moving anywhere or hit keyframe, velocity goes to 0 and because there is no statements that are going to flip object scale, so it goes to the start scale of [100, 100]. Numbers on screenshot is velocity - when it's negative - scale flips from [100, 100] to [-100, 100]
There is expression that I've been using;

if(transform.position.velocity[0]>0){
	[-100, 100]
}else{
	[100,100]
}


What I want to do is the object will remember his last scale number. So if we go from left to right, animation ends - object gonna safe his last scale. What do you think?

Screenshot 2022-11-30 at 19.25.34.pngScreenshot 2022-11-30 at 19.25.42.pngScreenshot 2022-11-30 at 19.25.46.png

TOPICS
Error or problem , Expressions

Views

460

Translate

Translate

Report

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 30, 2022 Nov 30, 2022

Something like this, probably:

if(transform.position.velocity[0]>0){
	[-100, 100]
}else if (transform.position.velocity[0]<0){
	[100,100]
}else{
  t = time - thisComp.frameDuration;
  gt = true;
  while(t >= inPoint){
    if (transform.position.velocityAtTime(t)[0] > 0){
      break;
    }else if (transform.position.velocityAtTime(t)[0] < 0){
      gt = false;
      break;
    }
    t -= thisComp.frameDuration
  }
  gt ? [-100,100] : [100,100]
}

Votes

Translate

Translate
LEGEND ,
Nov 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

It's all explained here:

 

http://www.motionscript.com/articles/speed-control.html

 

You need to integrate the values in a loop and then make determinations about the values based on some threshold.

 

Mylenium

Votes

Translate

Translate

Report

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
Explorer ,
Nov 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

Thank you for you reply, Mylenium! That's a beatiful article, I'll be glad to read it later. But I didn't quite understand how I can use this for my purpose? There is too many for me to understand what and where I can use it right now

Votes

Translate

Translate

Report

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 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

Something like this, probably:

if(transform.position.velocity[0]>0){
	[-100, 100]
}else if (transform.position.velocity[0]<0){
	[100,100]
}else{
  t = time - thisComp.frameDuration;
  gt = true;
  while(t >= inPoint){
    if (transform.position.velocityAtTime(t)[0] > 0){
      break;
    }else if (transform.position.velocityAtTime(t)[0] < 0){
      gt = false;
      break;
    }
    t -= thisComp.frameDuration
  }
  gt ? [-100,100] : [100,100]
}

Votes

Translate

Translate

Report

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
Explorer ,
Nov 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

It's beautiful!! It works exactly how I wanted! Thank you, Dan.

I don't quite understand what is going on here, but I'll take a closer look 🙂

Votes

Translate

Translate

Report

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 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

If the horizontal velocity is zero at the current frame, it backs up, frame-by-frame, until it finds the most recent frame where the horizontal velocity was non-zero and uses that value.

Votes

Translate

Translate

Report

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
Explorer ,
Nov 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

LATEST

Thanks a lot for your time Dan! I figured out how it works 🙂
It's actually pretty simple and clever when I started to realise how the whole script works

Votes

Translate

Translate

Report

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