Jump to content
Search Community

autoRotate immediateRender?

swampthang test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Using a bezier path, I'd love for there to be an option for autoRotate like immediateRender works for autoAlpha. In the pen, you see the plane starts off with no rotation and then abruptly rotates. Is there a way to accomplish this using any current settings? If I seek to something like 0.01, I get the initial rotation which is what I'd love to see right from the start.

See the Pen gQVRRQ?editors=0010 by swampthang (@swampthang) on CodePen

Link to comment
Share on other sites

Unless I'm missing something, I don't think it will do that.

 

I just calculate it myself. Using the next control point will point it in the right direction.

 

let bez = MorphSVGPlugin.pathDataToBezier(path);
let rotation = Math.atan2(bez[1].y - bez[0].y, bez[1].x - bez[0].x) + "_rad";
TweenMax.set(plane,{x: bez[0].x, y: bez[0].y, rotation });

 

  • Like 4
  • Thanks 1
Link to comment
Share on other sites

Awesome, Blake! Thanks. My app offers an image rotation knob so I added conversion to percentage so I could add as rotation offset value.

 

Here's a forked pen with that added in. You can set the rotationOffset and it'll add it. I set the rotation offset to -10 degrees.

 

See the Pen RqXyZX by swampthang (@swampthang) on CodePen

 

Edited by swampthang
Clarification of settings.
  • Like 1
Link to comment
Share on other sites

Yeah, it looks like you just have a weird path. The first control point is at the start (c0,0).

 

M95.6,505c0,0

 

You could check for that condition like this.

 

let p0 = bez[0];
let p1 = bez[1];
  
if (p0.x === p1.x && p0.y === p1.y) {
  p1 = bez[2];
}
  
let rad = (Math.atan2(p1.y - p0.y, p1.x - p0.x)) * (180 / Math.PI);

 

 

 

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Just wanted to add this to the codepen stack in case anyone might get something out of it. I'm setting transformOrigin for rotation to happen at the end of a path and added a draggable to a rotation knob and a box that stays centered around the end point of the path. You can rotate the knob or enter a new offset value in either of the 2 fields.

See the Pen vQLLMN?editors=0110 by swampthang (@swampthang) on CodePen

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...