Moving a node with your finger!


#1

Hello! I’m new to scripting in Zap.works and a modest programmer, so thanks in advance for your patience.

I would like to get into touch events, and want to start by moving a plane with a finger drag. Please note that I want to be able to move objects directly and not use the 3D Photofeature function.

I have a pointmove script for the plane with this script in it. I’m trying to access the array of the finger position using e.localPosition and feed that into the position method of the plane. I think the error means a variable type mismatch. Can anyone help?

parent.on(“pointermove”, (e) => {

var fingerPosition = ([e.localPosition]);
parent.position([fingerPosition]);

//Error thrown: Argument of type number [][][]`` is not assignable to parameter of typenumber []., //Typenumber []` is not assignable ot type number.

});


#2

Hi,
To correct your error you should write:

var fingerPosition = e.localPosition;
parent.position(fingerPosition);

but I don’t think it will work the way you want… :slight_smile:


#3

Thanks so much. Is there a better way to move an object around by touch?


#4

There is a problem because pointer is in 2D and the plane in 3D,
So a way, can be to “insert” the x,y of the pointer inside the 3D coordinates of the parent and keep the z value…

parent.on("pointermove", (e) => {
var fingerPosition = e.screenPosition;  // pointer position: x,y
var parentPosition = parent.position(); // plane position: x,y,z

parentPosition[0] = fingerPosition[0]; // replace the x
parentPosition[1] = fingerPosition[1]; // replace the y

parent.position(parentPosition);
});

#5

This worked! Thanks.

The odd thing is, the drag feels really unnatural. I’ll play with it to see if I can add a more realistic motion.

I appreciate your interest and help!