[SOLVED] Interesting Problem


(Bora Kasap) #1

I have two entities. Bullet and Enemy

Bullet Entity:

BULLET OVERRIDE
if (collide("enemy", x, y) && collidable)
			{
			
			hit.play();
			graphic = hitfx;
			hitfx.play("stand");
			firespeed = 0;
			FP.world.bringToFront(this);
			collidable = false;
			}
		
		if (hitfx.complete && firespeed == 0) { FP.world.remove(this); }

Enemy Entity:

ENEMY OVERRIDE
		if (collide("bullet", x, y))
			{
			armor -= FP.world.getInstance("playerx").bulletdamage;
			graphicfx.tinting = 0.5;
			fxtimer = 2;
			if (armor <= 0) { FP.world.remove(this); }
			}
			
		fxtimer --;
		if (fxtimer == 0) { graphicfx.tinting = 0; }

RESULT: Everything works fine in BULLET OVERRIDE. But, ENEMY is not detecting collision in ENEMY OVERRIDE. My think, Enemy should detect collision for one time because before collision the Bullet’s “collidable=true”;

Also both overrides have super.update(); at first lines. Actually i don’t know what is it…

And main settings: super(500, 500, 60, true);

All about timing. But how. When i remove “collidable=false” function from Bullet, enemy detecting collision. But why it is not detecting in same time with Bullet’s enemy detection.


(David Williams) #2

What may be happening is that the bullet is being marked for removal before the enemy detects the collision. What you could do is move all of the collision code for your bullet into a public function, and inside your enemy class, store a reference of the collide bullet, then run the function. So, maybe something like this:

        var b:BulletEntity = collide("bullet", x, y) as BulletEntity;
        if (b)
	{
                b.publicFunctionWithPreviousUpdateCodeHere();
		armor -= FP.world.getInstance("playerx").bulletdamage;
		graphicfx.tinting = 0.5;
		fxtimer = 2;
		if (armor <= 0) { FP.world.remove(this); }
	}

	fxtimer --;
	if (fxtimer == 0) { graphicfx.tinting = 0; }

(Bora Kasap) #3

it couldn’t be marked for removal, problem is not about that, because when i remove “collidable=false;” property function from bullet, enemy detects bullet. So, now, do you think it may be “marked for to be uncollidable” :smiley:


(Bora Kasap) #4

Actually, i’ve solved my problem by using triggered function to put enemy’s damage taking functions and i’m triggered it from bullet’s collision override function. Also that makes better performance. But, i haven’t solved the problem, i’ve just used another way… i want to solve problem still…


(David Williams) #5

Like you said, the bullet is turning collision off before the enemy detects it. If you could get the enemy to update before the bullet, then that wouldn’t happen.


(Bora Kasap) #6

Oh solved: this information is the first thing everybody have to learn…