LlApplyImpulse
| 首页 | 函数 | 事件 | 类型 | 操作符 | 常数 | Flow Control | Script Library | Categorized Library | Tutorials |
| 函数名 |
|---|
| Function: llApplyImpulse( vector momentum, integer local ); |
| 引用对对象应用脉冲 |
| •矢量动量
•整数局部-布尔值,如果真动量被视为局部方向向量,如果假动量被视为区域方向向量 瞬间冲动。llSetForce具有连续推送。”“瞬时”似乎意味着一秒钟的冲量,因为一个力(牛顿)的作用等于物体的质量(千克)持续一秒钟会使其加速到1的速度(米每秒),这似乎就是这个函数所发生的情况。 |
| 注意事项 |
|---|
| 只适用于支持物理的对象。
设置应用于质心的对象上的初始动量。动量是当物体不受其他力(如重力)影响时,获得初始速度运动所需的质量*速度 动量的大小可以被物体的可用能量缩小。对于重物体,动量的上限为动量=20000。(而不是之前所说的20)。对于快速物体,速度将被限制在202米/秒(因此动量将反映这个上限) |
| 示例 |
|---|
// Rez an object, and drop this script in it.
// This will launch it at the owner.
default
{
state_entry()
{
key ownerKey = llGetOwner();
vector ownerPosition = llList2Vector(llGetObjectDetails(ownerKey, [OBJECT_POS]), 0);
// if the owner is not in the sim, stop fooling around
if (llGetAgentSize(ownerKey) == ZERO_VECTOR)
return;
// else
llSetStatus(STATUS_PHYSICS, TRUE);
vector objectPosition = llGetPos();
vector direction = llVecNorm(ownerPosition - objectPosition);
llApplyImpulse(direction * 100, 0);
}
}
示例2 Make yourself a beer can, drop this script into it, and have some target practice.
vector gHome;
integer gHit;
default
{
collision_start(integer num)
{
if (!gHit)
{
llSetTimerEvent(15.0);
gHome = llGetPos();
gHit = TRUE;
}
llSetStatus(STATUS_PHYSICS, TRUE);
llTriggerSound("b90ed62a-2737-b911-bb53-6b9228bbc933",1.0);
llApplyImpulse(llGetMass()*<0,0,5.0>,TRUE);
llApplyRotationalImpulse(llGetMass()*<llFrand(1.0),llFrand(1.0),llFrand(1.0)>,TRUE);
llResetTime();
}
land_collision(vector where)
{
if (llGetTime() < 0.5)
{
llResetTime();
llApplyImpulse(llGetMass()*<0,0,llFrand(1.0)>,TRUE);
llApplyRotationalImpulse(llGetMass()*<llFrand(1.0),llFrand(1.0),llFrand(1.0)>,TRUE);
}
}
timer()
{
llSetStatus(STATUS_PHYSICS,FALSE);
gHit = FALSE;
llSetRegionPos(gHome); // Send the can home, even if more than 10m away
llSetRot(ZERO_ROTATION);
llSetTimerEvent(0.0);
}
}
// Uselesse script , just to demo that
// the parameter is a momentum not a force
// the initial velocity * mass = momentum when there are no other forces ( collisions, gravity )
// the momentum is not capped to 20
// momentum may be capped nevertheless because velocity is capped around 200 meters/second ; in this case it will be capped to 200m/s * mass
integer tid;
vector initPos;
vector Impulse;
default
{
state_entry()
{
llSetPhysicsMaterial(GRAVITY_MULTIPLIER,0,0,0,0);
llSetStatus(STATUS_PHANTOM, TRUE);
llSetStatus(STATUS_PHYSICS, TRUE);
}
touch_end(integer n)
{
tid=llTarget(initPos=llGetPos(),30);
llSetStatus(STATUS_PHYSICS, TRUE);
Impulse = llGetMass()*<0,0,25>;
llOwnerSay(llList2Json(JSON_ARRAY, [ "Setup a Momentum=", Impulse ]));
llApplyImpulse( Impulse , FALSE);
}
moving_start()
{
llOwnerSay(llList2Json(JSON_ARRAY, [ "Velocity= ", llGetVel(), "Force=",llGetMass()*llGetAccel(), "Momentum=", llGetVel()*llGetMass()]));
}
not_at_target()
{
llSetTimerEvent(0.0);
llTargetRemove(tid);
llSetStatus(STATUS_PHYSICS, FALSE);
llSetRegionPos(initPos);
}
}
// Example of results
// ["Setup a Momentum=","<0.000000, 0.000000, 183.181381>"]
// [10:19] Object: ["Velocity=","<0.000000, 0.000000, 25.000002>","Force=","<0.000000, 0.000000, -0.171902>","Momentum=","<0.000000, 0.000000, 183.181396>"]
// And for an heavy object, the cap is 20000
// ["Setup a Momentum=","<0.000000, 0.000000, 28244.332031>"]
// [11:01] Object: ["Velocity=","<0.000000, 0.000000, 17.702671>","Force=","<0.000000, 0.000000, -28.363781>","Momentum=","<0.000000, 0.000000, 20000.005859>
|
| 相关函数 |
|---|
| • llApplyRotationalImpulse
• llSetForce–设置连续力 |
| 相关事件 |
|---|
| 不可预测性
取自模拟器用户组/抄本/2012年10月5日 [16:24]Andrew Linden:llApplyImpulse()更不可预测 [16:24]安德鲁·林登:因为它使用了传统的脚本“能源预算” [16:25]Andrew Linden:如果脚本对象没有足够的“能量”来执行它想要的脉冲,这将减弱结果 [16:25]Andrew Linden:而且,llApplyImpulse()有很大的扭曲潜力 [16:25]Andrew Linden:所以我们很早以前就以很高的能耗率阻碍了它的发展 |