If i add script with code from APi it crashes, character model as right Physix character controller used with right API class, why crash ?
http://www.chi-ad.com/Skyline/API/Lua/html/classcontroller.html
- Code: Select all
function vector3()v3={x=0,y=0,z=0}return v3;end
obj = 0;
timer_Interval1 = 1000; --( time in ms ie 1000ms = 1sec )
walkSpeed = 2.0
rotDelay = 380; -- larger for quicker move
currentDelay = 0;
cYaw = 0;
posID = -1;
pos = vector3();
rayID = 0;
range = 10
RadiusOffset = 0.4;
function onInit(objID)
obj = objID;
controller.setData_Offset(0,-1.0,0);
controller.setData_characterHeight(1.0);
controller.setData_shapeType(0);
controller.setData_characterWidth(0.3);
controller.setData_stepOffset(0.4);
controller.setData_gravityY(-4);
controller.setData_slopeLimit(60);
controller.setData_flipDirection(0);
controller.setData_skinWidth(0.1);
controller.setData_upDirectionIndex(1);
dccID = controller.spawn(obj);
controller.setJumpDownforce(dccID,30);
spawnMarker();
rayID = physics.createRay();
physics.rayDebugLines(rayID,1);
end
function spawnMarker()
x,y,z = entity.getPosition(obj);
posID = entity.spawn("Cylinder_BarrelSize",x,y+0.5,z,1,1,1);
entity.setMaterialName(posID,"transparent");
pID = physics.addBody(posID,0, 1);
entity.setShadow(posID,0);
end
function onMouseDown( button, x, y )
pos.x,pos.y,pos.z = sky.raycastToCursor();
physics.setPosition(pID,pos.x,pos.y+0.5,pos.z);
moveSpd = walkSpeed;
end
function onUpdate( td )
x,y,z = entity.getPosition(obj)
dx,dy,dz = entity.getLocalOrientationByAxis( obj, 0,0,1 );
qw,qx,qy,qz = entity.getWorldOrientation(obj)
x=x+(dx*RadiusOffset);
y=y+(dy*RadiusOffset)+0.8;
z=z+(dz*RadiusOffset);
hitID,pox,posy,posz = physics.rayFromPoint(rayID, x,y,z,qw,qx,qy,qz,-range);
if(td>40) then td = 20; end
controller.move(dccID, moveSpd );
currentDelay = rotDelay * (td*0.001);
trackTarget();
if(controller.getCollisionFlag(dccID)==5 and moveSpd > 0) then
moveSpd = 0;
sky.trace();
end
end
function trackTarget()
entity.setRotation(obj, 0,0,0);
yawDeg = entity.getHeading(obj,posID);
cYaw = getYawLerp(cYaw, yawDeg);
entity.yaw(obj, cYaw, 0);
end
-- | Get the Yaw Lerped values.
function getYawLerp( currentYaw, yawDeg )
if( currentYaw > 180 ) then currentYaw = -180;
elseif( currentYaw < -180 )then currentYaw = 180; end
if(currentYaw >= yawDeg-currentDelay and currentYaw <= yawDeg+currentDelay )then
currentYaw = yawDeg;
else
if(currentYaw > 90 and yawDeg < -90 or currentYaw < -90 and yawDeg > 90 )then
if( currentYaw > yawDeg)then currentYaw = currentYaw + currentDelay;
elseif( currentYaw < yawDeg)then currentYaw = currentYaw - currentDelay; end
else
if( currentYaw > yawDeg)then currentYaw = currentYaw - currentDelay;
elseif( currentYaw < yawDeg)then currentYaw = currentYaw + currentDelay; end
end
end
return currentYaw;
end