Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by TommyBs

I'm trying to work out how I can make an Entity stop moving on touch of another Entity and when one is day, move again.

Say I have 2 sides, blue and red, when entities from either side collide with each other, though should battle (receiveDamage etc) until 1 of them is dead. When 1 entity is dead, the other should start moving again until it comes into contact with another entity from the opposite team. To begin with I'd have each entity inherit from a base class for a particular side e.g

EntityFoo = EntityBlue.extend;

EntityBar = EntityRed.extend;


I've created my own distanceToType function that checks how close entities are together, but I'm still a bit stuck. Currently the structure of the red entity is like

distanceToType: function(type,distance) {
    		var close = false;
            var types = ig.game.getEntitiesByType(type);
            for(var i =0 ; i < types.length; i ++){
                if(this.distanceTo(types[i]) < distance){
                    close = true;
                    break;
                }
            }
            return close;
        },
 collideWith:function(other,axis){

            this.parent(other,axis);
            this.vel.x = 0;
           	this.accel.x = 0;

        },
        check:function(other){
        	if(this.touches(other)){
        	this.vel.x = 0;
        	this.accel.x = 0;
        	this.istouching = true;
        	other.receiveDamage(1,this);
        }else{
        	this.istouching = false;
        }
        },

        update: function () {

            this.parent();
            if(!this.distanceToType(EntityBlue,8)){
           	 		this.accel.x = this.flip? -this.speed : this.speed;
                    this.currentAnim = this.anims.walking;
        	}else{
                this.currentAnim = this.anims.idle;
            }
        }

Extra info:
What's weird is that my entities are bouncing as well even with bounciness set to 0. All entities collide ACTIVE as well

Anyone got any ideas?

1 decade ago by TommyBs

Well I found out the best way to do what I want is actually using FIXED collision and the check function. There you go!
Page 1 of 1
« first « previous next › last »