E
E
Egorian2018-09-23 18:00:28
JavaScript
Egorian, 2018-09-23 18:00:28

phaser. Does the object go through the collision at high speed?

I'm making a game with a top view. I do so that the mouse does not go beyond the camera.

reticle = this.physics.add.sprite(player.x,player.y, 'reticle');
        reticle.setOrigin(0.5, 0.5).setCollideWorldBounds(true)
        reticle.body.allowGravity=false;  
 invisible_h = this.physics.add.group();
        createwall(invisible_h,false,0,0,"white-h",2,1)
        createwall(invisible_h,false,0,900,"white-h",2,1)
        createwall(invisible_h,false,player.x-900,0,"white",1,2)
        createwall(invisible_h,false,900,0,"white",1,2)
this.physics.add.collider(reticle,invisible_h)
this.input.on('pointermove', function (pointer) {
                if (this.input.mouse.locked)
                {
                    reticle.setVelocityX(pointer.movementX*60) 
                    reticle.setVelocityY(pointer.movementY*60) 
                }
            }, this)   
function update(){


reticle.setVelocityX(0);
reticle.setVelocityY(0);
// делает так чтобы мышка не отставала от игрока
reticle.body.velocity.x = player.body.velocity.x;
reticle.body.velocity.y = player.body.velocity.y;

}
function createwall(group,gravity,x,y,sprite,sx,sy){
    let wall= group.create(x,y,sprite);
    wall.body.allowGravity=false;
    wall.setScale(sx,sy)
    wall.body.immovable = true;
}

At first the mouse does not pass through the wall, but I move the reticle quickly, then it passes through it. How to solve this problem?
PS collision stops working at velocity>=1440. Maybe it has something to do with the refresh rate?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2018-09-23
@Egorian

It has to do with how physics is often considered. If the object on the previous "frame" of physics was, for example, to the left of something completely. and on the next frame of "physics" - already completely to the right - then there will be no collision - physics does not work with "teleports".
Solution methods:
- incorrect - increase the frequency of physics calculation
- correct - check if there are objects between the old and new positions. I will not suggest a verification method for a phaser.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question