“虚拟世界/脚本手册”的版本间的差异
| (未显示4个用户的10个中间版本) | |||
| 第1行: | 第1行: | ||
| − | {{ | + | {{VWSnav}} |
| + | ==示例== | ||
| + | ===动态纹理=== | ||
| + | *llSetTextureAnim( integer mode, integer face, integer sizex, integer sizey, float start, float length, float rate ); | ||
| + | **通过在特定面上设置材质的尺寸范围和偏移,让材质产生动画效果。 | ||
| + | **integer mode – mask of Mode flags | ||
| + | **integer face – face number or ALL_SIDES | ||
| + | **integer sizex – horizontal frames (ignored for ROTATE and SCALE) | ||
| + | **integer sizey – vertical frames (ignored for ROTATE and SCALE) | ||
| + | **float start – Start position/frame number (or radians for ROTATE),支持负数 | ||
| + | **float length – number of frames to display (or radians for ROTATE) | ||
| + | **float rate – frames per second (must not be zero),支持负数 | ||
| + | <pre> | ||
| + | default | ||
| + | { | ||
| + | state_entry() | ||
| + | { | ||
| + | llSetTextureAnim(ANIM_ON | SMOOTH | LOOP , ALL_SIDES, 1, 1, 1.0, 1.0, 1.0); | ||
| + | } | ||
| + | } | ||
| + | </pre> | ||
| + | *mode | ||
| + | **ANIM_ON 0x01 Texture animation is on. This must be set to start the animation, cleared to stop it. | ||
| + | **LOOP 0x02 Loop the texture animation. | ||
| + | **REVERSE 0x04 Play animation in reverse direction. | ||
| + | **PING_PONG 0x08 Play animation going forwards, then backwards. | ||
| + | **SMOOTH 0x10 Slide in the X direction, instead of playing separate frames.In both SCALE and ROTATE modes, causes smooth transitions. | ||
| + | **ROTATE 0x20 Animate texture rotation.Does not work with SCALE | ||
| + | **SCALE 0x40 Animate the texture scale.Does not work with ROTATE | ||
| − | + | ===旋转的风车=== | |
| + | #新建一些模型,设置选择中心为根连接物体 | ||
| + | #在根物体上设置脚本 | ||
| + | #llTargetOmega函数 | ||
| + | *llTargetOmega(vector axis, float spinrate, float gain) | ||
| + | *功能:使物体指定速度匀速平滑地旋转(即设置目标的旋转速度)。 | ||
| + | *axis: 供物体旋转的轴,会影响速度, (<0,0,2>,1,1)要比(<0,0,1>,1,1)旋转速度快一倍; | ||
| + | *spintate:旋转速度,为每秒的速度 | ||
| + | *gain:调节最终旋转力量,此参数只对物理对象其作用,对非物理对象,该参数值也不能为0。 | ||
| + | <pre> | ||
| + | default | ||
| + | { | ||
| + | state_entry() | ||
| + | { | ||
| + | llTargetOmega(<0,0,1>,PI,0.05); | ||
| + | } | ||
| + | } | ||
| + | </pre> | ||
| − | == | + | ===传送门=== |
| − | + | 点击一个物体传送到指定地点: | |
| − | + | #新建一个物体 | |
| − | + | #在“一般”属性中设置“点击以”“坐在物体上” | |
| − | {{ | + | #新建脚本 |
| + | <font color='red'>注意:</font>换算相对坐标时应该考虑物体自身的旋转量。某些基本物体在建造时是有初始的旋转量的(如:球为<0,90,0>)。 | ||
| + | <pre> | ||
| + | default | ||
| + | { | ||
| + | state_entry() | ||
| + | { | ||
| + | llSitTarget(<2.2,4.3,126.5>,ZERO_ROTATION);//设置目标地点相对物体的坐标值和旋转量,注意如果原物体有旋转,会影响相关结果 | ||
| + | llSetTimerEvent(0.1); | ||
| + | } | ||
| + | timer() | ||
| + | { | ||
| + | llUnSit(llAvatarOnSitTarget());//解除“坐下” | ||
| + | llSetTimerEvent(0.2);//0.2秒后执行timer() | ||
| + | } | ||
| + | } | ||
| − | |||
| − | |||
| − | + | 如果要实现跨岛传送,则用osTeleportAgent函数,可以如下实现: | |
| − | |||
| − | == | + | string Destination = "luguo2"; // 该参数是用来标识岛的名称; |
| − | {{ | + | vector LandingPoint = <128,128,50>; // 该参数用来标识X、Y、Z,代表到达目的地的坐标 |
| + | vector LookAt = <1,1,1>; // 该参数用来标识当到达时所面对的方向 | ||
| + | default | ||
| + | { | ||
| + | on_rez(integer start_param) | ||
| + | { | ||
| + | llResetScript(); | ||
| + | } | ||
| + | changed(integer change) // something changed, take action | ||
| + | { | ||
| + | if(change & CHANGED_OWNER) | ||
| + | llResetScript(); | ||
| + | else if (change & 256) // that bit is set during a region restart | ||
| + | llResetScript(); | ||
| + | } | ||
| + | state_entry() | ||
| + | { | ||
| + | llWhisper(0, "OS Teleportal Active"); | ||
| + | } | ||
| + | touch_start(integer num_detected) | ||
| + | { | ||
| + | key avatar = llDetectedKey(0);// 用于获取要传送的人(即接触物体的人); | ||
| + | llInstantMessage(avatar, "Teleporting you to : "+Destination); | ||
| + | osTeleportAgent(avatar, Destination, LandingPoint, LookAt); //最终的实现函数 | ||
| + | |||
| + | } | ||
| + | } | ||
| + | </pre> | ||
| + | |||
| + | ===时钟=== | ||
| + | 先建立一个面板,再建立时分秒针。秒针的模型建议是一个属性Slice B0.5 E1.0的被“切”掉一半的长方体,这样直接设置旋转量可以看出旋转效果。 | ||
| + | 以秒针为例,时分针类似。 | ||
| + | |||
| + | //llSetRot函数设置旋转量,llGetWallclock()函数可获取当前服务器上时间(全部累加换算成秒,比如1:01:01就是3661,如需要具体时分秒需进行简单换算),数据是float?还是integer? | ||
| + | default | ||
| + | { | ||
| + | state_entry() | ||
| + | { | ||
| + | llSetTimerEvent(0.3); | ||
| + | } | ||
| + | timer() | ||
| + | { | ||
| + | llSetRot(llEuler2Rot(<((integer)llGetWallclock()%60)*PI/30,0,0>)); | ||
| + | llSetTimerEvent(1); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | ===采蘑菇=== | ||
| + | 在一定空间内彩色蘑菇到处漂移,找到并点击他,他就被抓住了。 | ||
| + | #建立蘑菇盘,记录其位置 | ||
| + | #创建蘑菇,注意连接 | ||
| + | #编辑脚本 | ||
| + | <pre> | ||
| + | //设置蘑菇变化的基本位置 | ||
| + | vector gBase=<147,92,23>;//可以建立一个物体,然后设置位置 | ||
| + | //random distance | ||
| + | float gDistance_x=5; | ||
| + | float gDistance_y=5; | ||
| + | float gDistance_z=1; | ||
| + | //time | ||
| + | integer gTimechange=4; | ||
| + | //装蘑菇的盘子位置 | ||
| + | vector gContainer=<146.743,80.677,22.375>; | ||
| + | float gContainSize=0.5; | ||
| + | //communite channel | ||
| + | integer gCChannel=1; | ||
| + | |||
| + | default{ | ||
| + | state_entry(){ | ||
| + | llSetColor(<llFrand(1.0),llFrand(1.0),llFrand(1.0)>,ALL_SIDES); | ||
| + | llSetLinkColor(LINK_ALL_OTHERS,<llFrand(1.0),llFrand(1.0),llFrand(1.0)>,ALL_SIDES); | ||
| + | llSetTimerEvent(gTimechange); | ||
| + | llListen(gCChannel, "", "", ""); | ||
| + | } | ||
| + | touch_start(integer num_detected){ | ||
| + | llSetTimerEvent(0); | ||
| + | llSetPos(gContainer+<gContainSize*llFrand(gContainSize),gContainSize*llFrand(gContainSize),0>); | ||
| + | llSay(0,"Oh,Bing Catched!"); | ||
| + | } | ||
| + | timer(){ | ||
| + | llSetPos(gBase+<gDistance_x*llFrand(1.0),gDistance_y*llFrand(1.0),gDistance_z*llFrand(1.0)>); | ||
| + | } | ||
| + | listen( integer channel, string name, key id, string message ){ | ||
| + | if(message=="reset"){ | ||
| + | llResetScript(); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </pre> | ||
| + | |||
| + | ===坐在某个物体上=== | ||
| + | #新建一个元件,设置点击行为为:坐下 | ||
| + | #在该物体中增加脚本: | ||
| + | <pre> | ||
| + | default | ||
| + | { | ||
| + | state_entry() | ||
| + | { | ||
| + | llSitTarget(<0, 1.2, 1.2>, llEuler2Rot( <0.0, 0.0, 60.0> * DEG_TO_RAD )); | ||
| + | } | ||
| + | } | ||
| + | </pre> | ||
| + | *<0, 1.2, 1.2>,设置坐的位置,相对于物体的中心。注意需要考虑人本身的中心位置。 | ||
| + | *llEuler2Rot( <0.0, 0.0, 60.0> * DEG_TO_RAD ),设置坐的方向,相对旋转。 | ||
| + | |||
| + | ===开关门=== | ||
| + | #建一个门轴和门面 | ||
| + | #链接两个模型,让门轴为根物体(最后选中的) | ||
| + | #在根物体上建立以下脚本 | ||
| + | <pre> | ||
| + | integer vgIntDoorSwing = 90; | ||
| + | rotation vgRotDoorSwing; | ||
| + | default{ | ||
| + | state_entry(){ | ||
| + | vgRotDoorSwing = llEuler2Rot( <0.0, 0.0, vgIntDoorSwing> * DEG_TO_RAD ); | ||
| + | } | ||
| + | touch_start( integer vIntTouched ){ | ||
| + | vgRotDoorSwing.s *= -1; | ||
| + | llSetLocalRot( vgRotDoorSwing * llGetLocalRot()); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </pre> | ||
| + | |||
| + | ===粒子效果=== | ||
| + | #参数解释,请参考API手册,也可以通过名字猜猜。 | ||
| + | #首先在场景中建立一个正方体,然后在其“内容”属性中,新建脚本,复制下面的代码即可; | ||
| + | #要让粒子喷出指定的贴图,需要将贴图从资产库中拖到“内容”属性页下。 | ||
| + | <pre> | ||
| + | default { | ||
| + | state_entry() | ||
| + | { | ||
| + | llSetAlpha(0.0, ALL_SIDES); | ||
| + | llSetStatus(16,TRUE); | ||
| + | llParticleSystem( [ | ||
| + | PSYS_SRC_TEXTURE, llGetInventoryName(INVENTORY_TEXTURE, 0), //表示取得内容中的第一个材质,可以直接把资产库中的材质拖拽到内容中。 | ||
| + | PSYS_PART_START_SCALE, <0.25, 0.5, 0>, | ||
| + | PSYS_PART_END_SCALE, <0.25, 0.5, 0>, | ||
| + | PSYS_PART_START_COLOR, <0.856,0.723,0.203>, | ||
| + | PSYS_PART_END_COLOR, <0.856,0.203,0.234>, | ||
| + | PSYS_PART_START_ALPHA, 0.5, | ||
| + | PSYS_PART_END_ALPHA, 0.1, | ||
| + | |||
| + | PSYS_SRC_BURST_PART_COUNT, 7, | ||
| + | PSYS_SRC_BURST_RATE, 0.03, | ||
| + | PSYS_PART_MAX_AGE, 1.3, | ||
| + | PSYS_SRC_MAX_AGE, 0.0, | ||
| + | |||
| + | PSYS_SRC_PATTERN, 2, // 1=DROP, 2=EXPLODE, 4=ANGLE, 8=ANGLE_CONE, | ||
| + | |||
| + | PSYS_SRC_ACCEL, <0.0,0.0,-0.8>, | ||
| + | PSYS_SRC_BURST_RADIUS, 0.04, | ||
| + | PSYS_SRC_BURST_SPEED_MIN, 2, | ||
| + | PSYS_SRC_BURST_SPEED_MAX, 2, | ||
| + | |||
| + | PSYS_SRC_TARGET_KEY, llGetOwner(), | ||
| + | |||
| + | PSYS_SRC_ANGLE_BEGIN, 40*DEG_TO_RAD, | ||
| + | PSYS_SRC_ANGLE_END, 90*DEG_TO_RAD, | ||
| + | // PSYS_SRC_OMEGA, <0,0,0>, | ||
| + | |||
| + | // PSYS_SRC_TARGET_KEY, llGetLinkKey(llGetLinkNum() + 1), | ||
| + | |||
| + | PSYS_PART_FLAGS, ( 0 | ||
| + | | PSYS_PART_INTERP_COLOR_MASK | ||
| + | | PSYS_PART_INTERP_SCALE_MASK | ||
| + | | PSYS_PART_EMISSIVE_MASK | ||
| + | | PSYS_PART_FOLLOW_VELOCITY_MASK | ||
| + | // | PSYS_PART_WIND_MASK | ||
| + | // | PSYS_PART_BOUNCE_MASK | ||
| + | // | PSYS_PART_FOLLOW_SRC_MASK | ||
| + | // | PSYS_PART_TARGET_POS_MASK | ||
| + | // | PSYS_PART_TARGET_LINEAR_MASK | ||
| + | |||
| + | ) ] ); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </pre> | ||
2024年8月23日 (五) 08:48的最新版本
百科首页 - 3D虚拟世界 - 音乐与人工智能 - 人工智能机器人 - 知识百科 - 关于我们 - 网站首页
脚本首页 | Vehicles | NPC | HTTP | 脚本间通信 | 翻译参考
示例
动态纹理
- llSetTextureAnim( integer mode, integer face, integer sizex, integer sizey, float start, float length, float rate );
- 通过在特定面上设置材质的尺寸范围和偏移,让材质产生动画效果。
- integer mode – mask of Mode flags
- integer face – face number or ALL_SIDES
- integer sizex – horizontal frames (ignored for ROTATE and SCALE)
- integer sizey – vertical frames (ignored for ROTATE and SCALE)
- float start – Start position/frame number (or radians for ROTATE),支持负数
- float length – number of frames to display (or radians for ROTATE)
- float rate – frames per second (must not be zero),支持负数
default
{
state_entry()
{
llSetTextureAnim(ANIM_ON | SMOOTH | LOOP , ALL_SIDES, 1, 1, 1.0, 1.0, 1.0);
}
}
- mode
- ANIM_ON 0x01 Texture animation is on. This must be set to start the animation, cleared to stop it.
- LOOP 0x02 Loop the texture animation.
- REVERSE 0x04 Play animation in reverse direction.
- PING_PONG 0x08 Play animation going forwards, then backwards.
- SMOOTH 0x10 Slide in the X direction, instead of playing separate frames.In both SCALE and ROTATE modes, causes smooth transitions.
- ROTATE 0x20 Animate texture rotation.Does not work with SCALE
- SCALE 0x40 Animate the texture scale.Does not work with ROTATE
旋转的风车
- 新建一些模型,设置选择中心为根连接物体
- 在根物体上设置脚本
- llTargetOmega函数
- llTargetOmega(vector axis, float spinrate, float gain)
- 功能:使物体指定速度匀速平滑地旋转(即设置目标的旋转速度)。
- axis: 供物体旋转的轴,会影响速度, (<0,0,2>,1,1)要比(<0,0,1>,1,1)旋转速度快一倍;
- spintate:旋转速度,为每秒的速度
- gain:调节最终旋转力量,此参数只对物理对象其作用,对非物理对象,该参数值也不能为0。
default
{
state_entry()
{
llTargetOmega(<0,0,1>,PI,0.05);
}
}
传送门
点击一个物体传送到指定地点:
- 新建一个物体
- 在“一般”属性中设置“点击以”“坐在物体上”
- 新建脚本
注意:换算相对坐标时应该考虑物体自身的旋转量。某些基本物体在建造时是有初始的旋转量的(如:球为<0,90,0>)。
default
{
state_entry()
{
llSitTarget(<2.2,4.3,126.5>,ZERO_ROTATION);//设置目标地点相对物体的坐标值和旋转量,注意如果原物体有旋转,会影响相关结果
llSetTimerEvent(0.1);
}
timer()
{
llUnSit(llAvatarOnSitTarget());//解除“坐下”
llSetTimerEvent(0.2);//0.2秒后执行timer()
}
}
如果要实现跨岛传送,则用osTeleportAgent函数,可以如下实现:
string Destination = "luguo2"; // 该参数是用来标识岛的名称;
vector LandingPoint = <128,128,50>; // 该参数用来标识X、Y、Z,代表到达目的地的坐标
vector LookAt = <1,1,1>; // 该参数用来标识当到达时所面对的方向
default
{
on_rez(integer start_param)
{
llResetScript();
}
changed(integer change) // something changed, take action
{
if(change & CHANGED_OWNER)
llResetScript();
else if (change & 256) // that bit is set during a region restart
llResetScript();
}
state_entry()
{
llWhisper(0, "OS Teleportal Active");
}
touch_start(integer num_detected)
{
key avatar = llDetectedKey(0);// 用于获取要传送的人(即接触物体的人);
llInstantMessage(avatar, "Teleporting you to : "+Destination);
osTeleportAgent(avatar, Destination, LandingPoint, LookAt); //最终的实现函数
}
}
时钟
先建立一个面板,再建立时分秒针。秒针的模型建议是一个属性Slice B0.5 E1.0的被“切”掉一半的长方体,这样直接设置旋转量可以看出旋转效果。 以秒针为例,时分针类似。
//llSetRot函数设置旋转量,llGetWallclock()函数可获取当前服务器上时间(全部累加换算成秒,比如1:01:01就是3661,如需要具体时分秒需进行简单换算),数据是float?还是integer?
default
{
state_entry()
{
llSetTimerEvent(0.3);
}
timer()
{
llSetRot(llEuler2Rot(<((integer)llGetWallclock()%60)*PI/30,0,0>));
llSetTimerEvent(1);
}
}
采蘑菇
在一定空间内彩色蘑菇到处漂移,找到并点击他,他就被抓住了。
- 建立蘑菇盘,记录其位置
- 创建蘑菇,注意连接
- 编辑脚本
//设置蘑菇变化的基本位置
vector gBase=<147,92,23>;//可以建立一个物体,然后设置位置
//random distance
float gDistance_x=5;
float gDistance_y=5;
float gDistance_z=1;
//time
integer gTimechange=4;
//装蘑菇的盘子位置
vector gContainer=<146.743,80.677,22.375>;
float gContainSize=0.5;
//communite channel
integer gCChannel=1;
default{
state_entry(){
llSetColor(<llFrand(1.0),llFrand(1.0),llFrand(1.0)>,ALL_SIDES);
llSetLinkColor(LINK_ALL_OTHERS,<llFrand(1.0),llFrand(1.0),llFrand(1.0)>,ALL_SIDES);
llSetTimerEvent(gTimechange);
llListen(gCChannel, "", "", "");
}
touch_start(integer num_detected){
llSetTimerEvent(0);
llSetPos(gContainer+<gContainSize*llFrand(gContainSize),gContainSize*llFrand(gContainSize),0>);
llSay(0,"Oh,Bing Catched!");
}
timer(){
llSetPos(gBase+<gDistance_x*llFrand(1.0),gDistance_y*llFrand(1.0),gDistance_z*llFrand(1.0)>);
}
listen( integer channel, string name, key id, string message ){
if(message=="reset"){
llResetScript();
}
}
}
坐在某个物体上
- 新建一个元件,设置点击行为为:坐下
- 在该物体中增加脚本:
default
{
state_entry()
{
llSitTarget(<0, 1.2, 1.2>, llEuler2Rot( <0.0, 0.0, 60.0> * DEG_TO_RAD ));
}
}
- <0, 1.2, 1.2>,设置坐的位置,相对于物体的中心。注意需要考虑人本身的中心位置。
- llEuler2Rot( <0.0, 0.0, 60.0> * DEG_TO_RAD ),设置坐的方向,相对旋转。
开关门
- 建一个门轴和门面
- 链接两个模型,让门轴为根物体(最后选中的)
- 在根物体上建立以下脚本
integer vgIntDoorSwing = 90;
rotation vgRotDoorSwing;
default{
state_entry(){
vgRotDoorSwing = llEuler2Rot( <0.0, 0.0, vgIntDoorSwing> * DEG_TO_RAD );
}
touch_start( integer vIntTouched ){
vgRotDoorSwing.s *= -1;
llSetLocalRot( vgRotDoorSwing * llGetLocalRot());
}
}
粒子效果
- 参数解释,请参考API手册,也可以通过名字猜猜。
- 首先在场景中建立一个正方体,然后在其“内容”属性中,新建脚本,复制下面的代码即可;
- 要让粒子喷出指定的贴图,需要将贴图从资产库中拖到“内容”属性页下。
default {
state_entry()
{
llSetAlpha(0.0, ALL_SIDES);
llSetStatus(16,TRUE);
llParticleSystem( [
PSYS_SRC_TEXTURE, llGetInventoryName(INVENTORY_TEXTURE, 0), //表示取得内容中的第一个材质,可以直接把资产库中的材质拖拽到内容中。
PSYS_PART_START_SCALE, <0.25, 0.5, 0>,
PSYS_PART_END_SCALE, <0.25, 0.5, 0>,
PSYS_PART_START_COLOR, <0.856,0.723,0.203>,
PSYS_PART_END_COLOR, <0.856,0.203,0.234>,
PSYS_PART_START_ALPHA, 0.5,
PSYS_PART_END_ALPHA, 0.1,
PSYS_SRC_BURST_PART_COUNT, 7,
PSYS_SRC_BURST_RATE, 0.03,
PSYS_PART_MAX_AGE, 1.3,
PSYS_SRC_MAX_AGE, 0.0,
PSYS_SRC_PATTERN, 2, // 1=DROP, 2=EXPLODE, 4=ANGLE, 8=ANGLE_CONE,
PSYS_SRC_ACCEL, <0.0,0.0,-0.8>,
PSYS_SRC_BURST_RADIUS, 0.04,
PSYS_SRC_BURST_SPEED_MIN, 2,
PSYS_SRC_BURST_SPEED_MAX, 2,
PSYS_SRC_TARGET_KEY, llGetOwner(),
PSYS_SRC_ANGLE_BEGIN, 40*DEG_TO_RAD,
PSYS_SRC_ANGLE_END, 90*DEG_TO_RAD,
// PSYS_SRC_OMEGA, <0,0,0>,
// PSYS_SRC_TARGET_KEY, llGetLinkKey(llGetLinkNum() + 1),
PSYS_PART_FLAGS, ( 0
| PSYS_PART_INTERP_COLOR_MASK
| PSYS_PART_INTERP_SCALE_MASK
| PSYS_PART_EMISSIVE_MASK
| PSYS_PART_FOLLOW_VELOCITY_MASK
// | PSYS_PART_WIND_MASK
// | PSYS_PART_BOUNCE_MASK
// | PSYS_PART_FOLLOW_SRC_MASK
// | PSYS_PART_TARGET_POS_MASK
// | PSYS_PART_TARGET_LINEAR_MASK
) ] );
}
}