Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Animation question

hashemian
Contributor

Animation question

hashemian
Contributor
Contributor

This has been very challenging for me to get it to work.

I would appreciate any feedback on how to solve it.

I have a rotating hexagon or any other closed spline. I want to keep an object (i.e a rectangle) on top of it (without needing to manually keyframe its position at each frame . is there an easy way to do it?

I have attached screen grabs of what it should look like.

the purple rectangle should always sits on top of the rotating hexagon at each frame (moves up and down) and does not move left or right.

Thanks.

 

 

0 Likes
Reply
Accepted solutions (2)
1,247 Views
11 Replies
Replies (11)

leeminardi
Mentor
Mentor
Accepted solution

Use a Ray To Surface position controller.  I made 3D objects from the hexagon and rectangle so that I could pick a surface for the ray to hit.  The Ray Cast object is above the box.   Make a note of the direction of the local axis for the ray cast object.  For my example it was -Y and make sure the axis hit the hex surface. 

leeminardi_0-1650503455790.png

leeminardi_1-1650503788130.png

 

 

lee.minardi
0 Likes

ahashemian
Community Visitor
Community Visitor

Thanks, but the solution doesn't seem to work, rotating the hexagon and you see the box does not seem to stay on top of the hexagon at all time

0 Likes

leeminardi
Mentor
Mentor

The Ray-To-surface controller does not always give precise result.  It may have some difficulty when the rotating hex surface edge is directly in line with the ray.

 

Here's anther solution this should be very precise and accurate.  In the attached file is used a position script for the rectangle.  The expression relating the vertical (y) position of the rectangle  to the rotation angle (theta) of the hexagon took a little thought.  When using Euler rotation controllers it is possible to get angles > 360ยฐ. In addition, allowance has to be made that every 60ยฐ of rotation the rectangle comes in contact with another surface.  The expression I came up with is:

alpha = abs(theta - 2* (mod theta 30) - 60.0 * integer(theta/60))
hex_pos + [ 0, r*cos(alpha),0]

Alpha is the angle used by the cosine function to determine the Y coordinate of the rectangle.  The mod function is used to get the remainder of the angle for every 60ยฐ.   Converting theta/60 to an integer provides a multiplier for every additional 60ยฐ of rotation.

 

I think it works very well!

leeminardi_0-1650585775451.png

 

You can change the size of the hexagon or move it and the rigging will still work.

 

lee.minardi
0 Likes

domo.spaji
Advisor
Advisor

@leeminardi wrote:

The Ray-To-surface controller does not always give precise result.

 

It's not bout controller precision, for this shapes and their sizes solution is box minimum = hexagonal prism maximum (Z) and with "Ray-To-surface" it (can) happen only 2 times (in 1/6 of 360 deg rotation )

 

There's no function that would work for every shapes and sizes!

 

Can't get out from quote!!??

0 Likes

hashemian
Contributor
Contributor

Thank you for your time. While this solution works only for a hexagon with its pivot point at the center, it will not work for a rotating hexagon with it's pivot point not at the center (like the images I originally posted). I am looking for a solution that works with shapes/objects that can be irregular (i.e an ellipse or egg shape..)

maybe I should look into a script that keyframes a "z-axis " max to min alignment between the 2 objects at each frame..

I wish there was a controller that could keep an object always on top of the boundary box of another object..

 

 

0 Likes

leeminardi
Mentor
Mentor

@hashemian I missed in the image that the pivot was not centered.

Can the shapes you will want to use be approximated by a convex hull (i.e., no concave segments)?

lee.minardi
0 Likes

hashemian
Contributor
Contributor

yes.

Thanks.

 

0 Likes

leeminardi
Mentor
Mentor
Accepted solution

Here's a clean, accurate, and precise solution for any line that defines a convex hull shape.

I wrote it to work on the XY plane and place the rectangles pivot above the rotating shape's pivot.

The rectangle has the following position script where LineShape is referencing the line object.

ymax = (getKnotPoint LineShape 1 1).y
for i = 2 to NumKnots LineShape Do
(
  vert = getKnotPoint LineShape 1 i
  if (vert.y > ymax) then ymax = vert.y
)
[LineShape.controller.position.x, ymax,0]

leeminardi_0-1650749402915.png

 

 

lee.minardi
0 Likes

hashemian
Contributor
Contributor

Thanks so much,

Will you be able to back-save the file in 2021 or 2020?
Thanks.

 

0 Likes

leeminardi
Mentor
Mentor

Here's a 2020 version of the file.   The ray direction axis is Y. I could modify the script to reference a ray casting object if needed.

Lee

 

 

lee.minardi
0 Likes

hashemian
Contributor
Contributor

this is absolutely the solution I was looking for.

I appreciate it.

Thanks so much.

 

0 Likes