#Help needed with scripting!
9 messages · Page 1 of 1 (latest)
I need to have the same effect as a Ender dragon egg from Minecraft (Sudden and quick teleportation) lol
Made a simple script, but can't get it to work with the object...
//@input SceneObject dragonEgg
//@input float radius = 1.0
function getRandomPosition(radius) {
var angle = Math.random() * Math.PI * 2;
var x = Math.cos(angle) * radius;
var z = Math.sin(angle) * radius;
return new vec3(x, 0, z);
}
function onTap(eventData) {
var randomPosition = getRandomPosition(script.radius);
script.dragonEgg.getTransform().setLocalPosition(randomPosition);
}
var tapEvent = script.createEvent("TapEvent");
tapEvent.bind(onTap);
You mean tap should work only on the object and not on entire screen.
I think that is what she means. If that is the case: @timber grove try looking into Raycasting, what it does is creating a invisible line from 2d (your fingers X,Y coord) to 3d world space X,Y,Z. When that ray is hitting an object it wil return it and in that case you can move it again to another position.
Here you find how to do it: https://developers.snap.com/lens-studio/features/physics/raycast
If it's just tapping then there's no need to Raycast, one can simply use the Interaction Component, that will easily detect tap and coding it is very easy.
You could be right. I've never used that one