The lag effect of entity behavior


#1

I create model entities using javascript and set it can collide with other entities, but after the model is creasted, it can’t collide with other entities in most cases. And only after I restart the sandbox server, the collision take effect. Below is my code, can anyone help me?:

(function() {
var count=0
var array=[]
var collideObjNames=[“terrain”]
var dis=0.4

function disLessThan(p1,p2){
    var temp=p1-p2;
    if(temp<-dis||temp>dis)
        return false
    return true
}

function getEntityPosition(id){
    return Entities.getEntityProperties(id, ["position"]).position
}

function hasPointAround(px,py,pz){
    for(var i=0;i<array.length;i++){
        tank=getEntityPosition(array[i])
        print("------------------------------: "+tank.x+"  "+tank.y+"   "+tank.z)
        if(disLessThan(px,tank.x)&&disLessThan(pz,tank.z)&&disLessThan(py,tank.y))
            return true
    }
    return false
}

function canCollideWith(id){
    name=Entities.getEntityProperties(id, ["name"]).name
    print("++++++++++++++++++++++:"+name)
    for(var i =0;i<collideObjNames.length;i++){
        if(name==collideObjNames[i])
            return true
    }
    return  false
}

this.collisionWithEntity = function(myID, otherID, collisionInfo) {
    print(myID+"ccccccccccccccccccccc"+Entities.getEntityProperties(otherID, ["name"]).name+"cccccccccccccccccccccccccccccccc"+collisionInfo.contactPoint.x);

    if(!hasPointAround(collisionInfo.contactPoint.x,collisionInfo.contactPoint.y,collisionInfo.contactPoint.z) && canCollideWith(otherID)){
        var tank_URL="http://162.105.17.187/3dmodel/tank3/tank3.fbx"
        var tank = Entities.addEntity({
            type: "Model",
            modelURL: tank_URL,
            name: "tank",
            position: collisionInfo.contactPoint,
            rotation: {x:0,y:0,z:0,w:0},
            dimensions: {x: 0.15,y: 0.04,z: 0.07},
            gravity:{x:0.0, y:-0.0005, z:0.0},
            registrationPoint: {x:0,y:0,z:0},
            dynamic: true,
            collisionless: false,
            shapeType:"box",
            damping:0.99,
            angularDamping:0.99

        });
        array.push(tank)
        print("-----------------------------------------tank number: "+array.length)

        count+=1
        print(count+"*************************************************")
    }
}

});


#2

Hi. You probably need to give it a little velocity kick to start up the physics, for example:
velocity: { x: 0, y: 0.02, z: 0 }
Try including that in the properties when you do Entities.addEntity(). If that doesn’t work, try doing a Entities.editEntity() on the tank after the Entities.addEntity().