Flickering problem in globe

The ball, the main ball of the game, vibrates when the game starts

Hi @Ozden_Delibas,

Try sharing more details about the issue, like video, build url, or a project editor url.

Together with the setup you are using e.g. component settings, and your expected outcome.

Otherwise it’s quite impossible for users to help you out.

1 Like

What causes the tremor in the sphere

How are you moving it?

It looks like it’s the framerate dropping. If you look at the arrow in the back it also stutters when the ball rolling does. I played this game on my desktop with no issues which makes me think that the issue is heavy logic being completed during the update() loop.

1 Like
var Controller = pc.createScript('controller');

Controller.attributes.add('speed', {
   type: 'number',
    default: 3
});

Controller.attributes.add('direction_speed',{
   type: 'number',
    default: 17
});

Controller.attributes.add('count',{
   type: 'number',
    default: 2
});

Controller.attributes.add('countText',{
   type: 'entity'
});


Controller.attributes.add("sceneId",{
    type:"string",
    default: "0",
    title: "New Level"
});
Controller.attributes.add("sceneIdd",{
    type:"string",
    default: "0",
    title: "Return"
});



// initialize code called once per entity
Controller.prototype.initialize = function() {
    this.entity.collision.on('collisionstart', this.onCollisionStart, this);
    this.app.off("rotator:point");
    this.app.on("rotator:point", this.onPoint, this);
    this.countText.element.text = " 2";
    
    this.entity.collision.on('triggerenter', this.onTriggerEnter, this);
    
    this.sagButton = this.app.root.findByName('SagButton');
    this.solButton = this.app.root.findByName('SolButtton');
    
    // buttons state
    this.isSagPressed = false;
    this.isSolPressed = false;
    
    // remove old event listenrs
    this.sagButton.element.off('mousedown');
    this.sagButton.element.off('mouseup');
    this.sagButton.element.off('touchstart');
    this.sagButton.element.off('touchend');
    
    
    this.solButton.element.off('mousedown');
    this.solButton.element.off('mouseup');
    this.solButton.element.off('touchstart');
    this.solButton.element.off('touchend');
    
    //add new event listeners
    this.sagButton.element.on('mousedown', this.onSagDown, this);
    this.sagButton.element.on('mouseup', this.onSagUp, this);
    this.sagButton.element.on('touchstart', this.onSagDown, this);
    this.sagButton.element.on('touchend', this.onSagUp, this);
    
    this.solButton.element.on('mousedown', this.onSolDown, this);
    this.solButton.element.on('mouseup', this.onSolUp, this);
    this.solButton.element.on('touchstart', this.onSolDown, this);
    this.solButton.element.on('touchend', this.onSolUp, this);
     let sphere = pc.app.root.findByName('Toplar').findByName('Sphere');
     sphere.model.meshInstances[0].material.diffuse.set(90/255, 90/255, 90/255); 
     sphere.model.meshInstances[0].material.update();
    
    if (pc.platform.mobile) {
     
    }
    if (pc.platform.windows) {
    // touch is supported 
}
    
};

Controller.prototype.onSagDown = function(event){
    this.isSagPressed = true;
};

Controller.prototype.onSagUp = function(event){
    this.isSagPressed = false;
};

Controller.prototype.onSolDown = function(event){
    this.isSolPressed = true;
};

Controller.prototype.onSolUp = function(event){
    this.isSolPressed = false;
};

Controller.prototype.update = function(dt) {
    

    var rb = this.entity.rigidbody;
    var direction_rb = this.entity.rigidbody;
    var moveHoriz = 0;
    var moveVert = 0;
    var direction_moveHoriz = 0;
    var direction_moveVert = 0;
    
    // Mobil alanda ve masaüstü sistemde oldugunu anlamak için yazılan kodlar
    // Bu kodlar tamam 

    if (pc.app.mouse) {
            if(this.app.keyboard.isPressed(pc.KEY_LEFT))            {direction_moveHoriz = 1;}
            if(this.app.keyboard.isPressed(pc.KEY_RIGHT))           {direction_moveHoriz = -1;}
            this.app.root.findByName('SagButton').enabled=false;
            this.app.root.findByName('SolButtton').enabled=false;
    }
    
    if(this.app.touch){
            if(this.isSolPressed)           {direction_moveHoriz = 1;}
            if(this.isSagPressed)           {direction_moveHoriz = -1;}
            this.app.root.findByName('SagButton').enabled=true;
            this.app.root.findByName('SolButtton').enabled=true;
    }
    

    if(this.speed <= 3){
         moveVert = -1;
    } else this.speed = 3;
    var moveVect = new pc.Vec3(moveVert, 0, moveHoriz);
    rb.applyForce(moveVect.scale(this.speed));
    var direction_moveVect = new pc.Vec3(direction_moveVert, 0, direction_moveHoriz);
    direction_rb.applyForce(direction_moveVect.scale(this.direction_speed));
    
    
};

You will want to avoid using this.app.root.findByName() in your update() function. This is a very expensive to call every frame as the app will have to search all of the entities in the scene up to 60 times per second to find the correct entity.

You will also want to avoid creating new pc.Vec3()'s in the update() loop as that can be expensive as well. Create one in initialize() and update it with the values you need.

3 Likes

Make sure you update your camera position (as it tracks the ball) in a postUpdate function and not update.

2 Likes