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 Alex

How do you check if Entity doesn't overlap, then do { ... } ?

I know

check: function( other ) { ... }

But how do you write if not?

Basically I'm trying to check if it's free to add another entity at pos.x/y. So I thought of adding an invisible "scout" entity there that'll check if no one's there, then add the real visible entity.

1 decade ago by Alex

so people know if have same question:

[01:56:27] <domsz> have a isOverlapping var in your scout entity that is set to false by default
[01:56:39] <domsz> when check() is called, set it to true
[01:57:21] <domsz> however, you'd have to check the isOverlapping var one frame later, as the collision detection is done after update() is called

build scout entity:
	check: function( other ) {
		this.isOverlapping = 1;
	},
	
	update: function() {
		if(this.framepassed) {
			if(this.isOverlapping == 1) { this.kill(); console.log('overlaps'); }
			else { console.log('doesnt'); /* then do whatever you want here */ }
		}
		this.framepassed = 1;
	}
Page 1 of 1
« first « previous next › last »