Scripts de Avatar
Los scripts de avatar están vinculados y limitados a un avatar. Esto significa que se ejecutan cuando un usuario pone en escena un avatar específico. Del mismo modo, los scripts de avatar dejan de ejecutarse cuando se elimina o se cambia el avatar. Otros usuarios en el dominio podrán ver el script en acción, pero no podrán ejecutarlo ellos mismos.
Con los scripts de avatar, puedes hacer cosas como hacer que el cabello se mueva o crear nubes de partículas alrededor de tu avatar.
En Esta Página
Añade un Script de Avatar
There are two different ways you can add an avatar script to your FST file: either by using our Package Model tool or by manually adding the script.
To add an avatar script using the Package Model tools:
Create a folder called
scripts
in the same location as your FBX, GLB, or glTF file.Copy your avatar script into this new folder.
In Interface, go to Edit > Package Model as .fst
For 'Script Directory', enter the path to the
scripts
folder you created above.
To add an avatar script manually:
Open the FST file for your avatar in the text editor of your choice.
Add a line telling the avatar where to find the script file using the syntax
script = [SCRIPT URL]
.
You can add multiple scripts to your avatar by adding multiple script = url
lines.
Example of an Avatar Script
The following script makes your avatar throw balls when its right hand moves.
(function(){
var triggerDistance = 0.0;
var TRIGGER_THRESHOLD = 0.9;
var LOAD_THRESHOLD = 0.6
var init = false;
var rightHandIndex = MyAvatar.getJointIndex("RightHand");
var rightArmIndex = MyAvatar.getJointIndex("RightArm");
var distance = 0.0;
var triggered = false;
function fireBall(position, speed) {
var baseID = Entities.addEntity({
type: "Sphere",
color: { blue: 128, green: 128, red: 20 },
dimensions: { x: 0.1, y: 0.1, z: 0.1 },
position: position,
dynamic: true,
collisionless: false,
lifetime: 10,
gravity: speed,
userData: "{ \"grabbableKey\": { \"grabbable\": true, \"kinematic\": false } }"
});
Entities.editEntity(baseID, { velocity: speed });
}
Script.update.connect(function() {
rightHandPos = MyAvatar.getJointPosition(rightHandIndex);
rightArmPos = MyAvatar.getJointPosition(rightArmIndex);
fireDir = Vec3.subtract(rightHandPos, rightArmPos);
var distance = Vec3.length(fireDir);
triggerDistance = distance > triggerDistance ? distance : triggerDistance;
if (!triggered) {
if (distance < LOAD_THRESHOLD * triggerDistance) {
triggered = true;
}
} else if (distance > TRIGGER_THRESHOLD * triggerDistance) {
triggered = false;
fireBall(rightHandPos, Vec3.normalize(fireDir));
}
});
MyAvatar.scaleChanged.connect(function () {
triggerDistance = 0.0;
});
}());
This example script uses the MyAvatar namespace to determine if your avatar's hand moves. Upon detecting movement, the script makes your avatar launch balls. It also uses some other namespaces such as Entities (to create the ball you will launch) and Vec3 (to determine the right positions and distances). Add it to your avatar to see how it works.
Ver también
Primeros pasos con Scripting
Escribe tus propios Scripts