# Follow Eyes Rotation to object position

Hi guys! I face the issue to convert Eyes Rotation and change the position of the obj

``````//@input Component.Head head
//@input SceneObject obj

var xChange = 0;
var yChange = 0;
var zChange = 0;

function onUpdate(){
distanceChange();
set();
}

script.createEvent('UpdateEvent').bind(onUpdate);

function distanceChange(){

//clamp
xChange = Math.max(-2, xChange);
xChange = Math.min(1, xChange);
yChange = Math.max(-1, yChange);
yChange = Math.min(1, yChange);
}

function set(){
// var rot = script.obj.getTransform().getWorldPosition();
if(xChange >= 0){
var newPosition = new vec3 (xChange, yChange, zChange);
script.obj.getTransform().setWorldPosition(newPosition);

}
if(xChange < 0){
var newPosition = new vec3 (xChange,yChange, zChange);
script.obj.getTransform().setWorldPosition(newPosition);
}
}
``````

What kind of values are you getting, and what values do you want? Itβs hard to see what the problem is just by looking at the script. Are you sure the world rotation is in euler angles? You might need to convert it from quaternion.

yeah, maybe Iβm thinking in the wrong way
I have to convert my EyeBall Rotation to the vec3 position.
I know it has a formula where I need to convert rotation to Euler and then Euler to vec3 coordinates or something like this

now I get it that I can convert Rotatio toEuler()
and now I stuck how to convert toEuler cordinates to position movement

Euler is already a vec3. I would start by taking y rotation for x position and x rotation for y position. Then you can do some multiplication or value remapping to get it into the range you want.

1 Like