Skip to main content
Participant
August 2, 2024
Answered

Glitchy values in CC Sphere with expressions

  • August 2, 2024
  • 3 replies
  • 270 views

Hello,

 

I’m have a few pseudo-spheres using CC Sphere, that I am moving around. To simulate a common lighting (from the top left), I have some expressions in the Light Height and Light Direction of all the spheres.

 

It kinda works, but it’s glitchy: the lighting jumps from one condition to another at seemingly random moments, and not for every sphere at the same time.

 

See the attached reduced debug file, with only one sphere. Watch the animation in full. Instead of being smooth, the lighting jumps, for instance at 0:00:01:12, at 0:00:03:05, at 0:00:04:18, at 0:00:10:19, etc.

I’m using these expressions:

Light Height:

100 - Math.sqrt(transform.xPosition^2 * transform.yPosition^2)*2

(Pythagoras to get the distance from the top left corner and scale it to the property)

 

Light Direction:

-radiansToDegrees(Math.atan(transform.xPosition/transform.yPosition))

(Trygonometry to get the angle from the top left corner)

 

Could someone help me find out what’s actually happening? Thanks!

This topic has been closed for replies.
Correct answer nicolas-f

Found the culprit!

 

I was using ^2 thinking it meant power of two:

100 - Math.sqrt(transform.xPosition^2 * transform.yPosition^2)*2

 

But it actually was something else and I had to use Math.pow(,2) instead:

100 - Math.sqrt(Math.pow(transform.xPosition,2) * Math.pow(transform.yPosition,2))*.0001-40

(with some magic numbers at the end to scale it as looked good)

3 replies

nicolas-fAuthorCorrect answer
Participant
August 2, 2024

Found the culprit!

 

I was using ^2 thinking it meant power of two:

100 - Math.sqrt(transform.xPosition^2 * transform.yPosition^2)*2

 

But it actually was something else and I had to use Math.pow(,2) instead:

100 - Math.sqrt(Math.pow(transform.xPosition,2) * Math.pow(transform.yPosition,2))*.0001-40

(with some magic numbers at the end to scale it as looked good)

Mylenium
Legend
August 2, 2024

You will need to add a conditional to account for values larger than 180 degrees. The internal math of the effect simply flips over. I also think you need to add 90 degrees/ Half Pi somewhere to offset the angles correctly.

 

Mylenium

nicolas-fAuthor
Participant
August 2, 2024

(in green and red, how smooth are my xPos and yPos; in yellow, how jumpy is my “Light Height”)