Javascript sin math

Hello everyone,

I managed to create a small 3D environment for my model… I’d like to showcase it interactively etc.
This will be an ongoing work, as every day I learn more and more.

Just in case this is the link to the project

I have a question on how to script something in here.
I made a light map for the light on the back of the controller.
emissiveIntensity controls how much the light will be visible. What I’d like to achieve is having the light “pulsing” on and off. To do that I’d like to use the classical Math.sin() method.
Problem is that I usually use it on After Effects, having Math.sin(time), where time takes the returns the actual frame using it as radiant for the function.
Problem is that I don’t have a timeline using three.js

Does someone know what can I use instead of time to have a value that keeps changing from -1 to 1 {or better from 0 to 1 as the emissiveIntensity value goes from 0 to 1}?

Many thanks to everyone!

Something like that:

var clock = new THREE.Clock();

// in your render loop
materialeDualshock.emissiveIntensity = Math.sin(clock.getElapsedTime()) * 0.5 + 0.5;

Vewry kind…
It worked perfectly.

This will go on slowly slowly but I like the result and it inspired me to do more with three.js!

You’re welcome :slight_smile: :beers:
If you want to blink it faster or slower, just multiply the argument of sin function with desired value. The greater value you use, the faster it blinks.