testOverlap is not working on low impulse

0 favourites
  • 3 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • Hello!

    I've got alot of similar sprites with Sprite_obj%number% name. They all have physics behavior.

    When for example Sprite_obj1 is on collision with another Sprite_obj1 I need them to be destroyed and create Sprite_obj2 instead.

    For Sprite_obj2 same but create Sprite_obj3

    Everything is ok as long as I use event "on collision" for each Sprite_obj.

    But when I try to use script, it only works when Sprite_objs hit each other hard.

    If I just place them on top of each other with couple of px between it wouldn't work.

    import GlobalVars from "./globalVars.js";
    
    export function Tick(runtime){
    
    	const dt = runtime.dt;
    	
    	HandleCollision(runtime, "Sprite_obj1", "Sprite_obj2");
    	HandleCollision(runtime, "Sprite_obj2", "Sprite_obj3");
    	HandleCollision(runtime, "Sprite_obj3", "Sprite_obj4");
    	HandleCollision(runtime, "Sprite_obj4", "Sprite_obj5");
    	
    	for (const starsInstance of runtime.objects.Stars.instances())
    	{
    		FadeStars(starsInstance, dt);
    	}
    }
    
    function HandleCollision(runtime, Sprite1, Sprite2) {
     const stars = runtime.objects.Stars;
    	const Sprite = runtime.objects[Sprite1];
    	const instances = Sprite.getAllInstances();
    	for (let i = 0; i < instances.length; i++) {
     for (let j = i + 1; j < instances.length; j++) {
     if (instances[i].testOverlap(instances[j])) {
    				const scoreInstance = runtime.objects.TestText.getFirstInstance();
    				scoreInstance.text = GlobalVars.test;
    				const newSprite = runtime.objects[Sprite2].createInstance("Game", instances[i].x, instances[i].y);
    				const starsInstance = stars.createInstance("Game", newSprite.x, newSprite.y);
    				starsInstance.isVisible = true;
    				starsInstance.angleDegrees = runtime.random() * 360;
     instances[i].destroy();
     instances[j].destroy();
     }
     }
     }
    }
    

    Can anyone help me with this?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Can you repeat the problem in a new project and upload the file? Or write to me on discord.

  • The physics behavior triggers on collision when it’s it detects a collision and does a collision response.

    Typically the collision is fully resolved so there’s no overlap by the time a user added overlap check is done. It doesn’t when there’s a high impulse because it sometimes can take a few frames to push things apart in the physics engine.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)