Copy link to clipboard
Copied
This is my code, I am getting no errors but the eye are not moving.
var root = this;
var container, var1, var2, var3, radius1, radius2, eyeR, eyeL;
var shapes = [];
function main()
{
root.stop();
container = root.container;
eyeR = root.eyeR;
eyeL = root.eyeL;
container.mouseChildren = false;
eyeR.mouseChildren = false;
eyeL.mouseChildren = false;
stage.enableMouseOver(20);
container.on("mouseMove", mouseMoved);
}
function mouseMoved(e)
{
var1 = e.stageY - 270 / stage.scaleY;
var2 = e.stageX - 380 / stage.scaleX;
var3 = e.stageX - 580 / stage.scaleX;
radius1 = Math.atan2(var1,var2);
radius2 = Math.atan2(var1, var3);
eyeR.setTransform(580,270,1,1,radius2);
eyeL.setTransform(380,270,1,1,radius1);
}
main();
This is how I made it work in P5.js and ActionScript for refernce on how it should work.
https://editor.p5js.org/JWNimble/sketches/4-cBgdHkH
ActionScript Code
stage.addEventListener("mouseMove", arjun);
function arjun(e:MouseEvent):void
{
var var1 = mouseY - eyeR.y;
var var2 = mouseX - eyeR.x;
var radiusR = Math.atan2(var1,var2);
var degreeR = radiusR / (Math.PI / 180);
eyeR.rotation = degreeR;
var var3 = mouseY - eyeL.y;
var var4 = mouseX - eyeL.x;
var radiusR1 = Math.atan2(var3,var4);
var degreeR1 = radiusR1 / (Math.PI / 180);
eyeL.rotation = degreeR1;
}
Copy link to clipboard
Copied
use console.log() to debug. for example:
ar root = this;
var container, var1, var2, var3, radius1, radius2, eyeR, eyeL;
var shapes = [];
function main()
{
root.stop();
container = root.container;
eyeR = root.eyeR;
eyeL = root.eyeL;
container.mouseChildren = false;
eyeR.mouseChildren = false;
eyeL.mouseChildren = false;
stage.enableMouseOver(20);
container.on("mouseMove", mouseMoved);
}
function mouseMoved(e)
{
var1 = e.stageY - 270 / stage.scaleY;
var2 = e.stageX - 380 / stage.scaleX;
var3 = e.stageX - 580 / stage.scaleX;
radius1 = Math.atan2(var1,var2);
radius2 = Math.atan2(var1, var3);
eyeR.setTransform(580,270,1,1,radius2);
eyeL.setTransform(380,270,1,1,radius1);
console.log(eyeR,radius2);
}
main();
Copy link to clipboard
Copied
I have been, it returns no errors though
Copy link to clipboard
Copied
what's a portion of the console output from the code i suggested?
Copy link to clipboard
Copied
i just tested your code and you can see from the console.log() that mouseMoved is not being called. meaning your "mouseMove" listener is problematic. and in fact there is no "mouseMove", though "mousemove" would be a better try, but it doesn't exist either.
check the stage. it has a "stagemousemove" listener you can use:
stage.addEventListener("stagemousemove",mouseMoved.bind(this));
Copy link to clipboard
Copied
you have locked my previous post on this but I still would like to figure out what is going one with the rotational angles of the eyes, now that it is actually rotating.
Copy link to clipboard
Copied
I think that Math.atan2 works in radians, and setTransform works in degrees.
Copy link to clipboard
Copied
@Colin Holgate, is correct. you have to convert from radians to degrees:
eyeL.setTransform(380,270,1,1,180*radius1/Math.PI);