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 Rapt

Hi, I'm new to javascript, and to impact.

I was trying to make my player to move crates which was very easy, but I want that when it tries to move a crate that is colliding with another one neither the crates nor the player can move. Like chon's boxes game

I had triying this

		collideWith: function(other,axis){
			if(other.isBox){
				var player = ig.game.getEntitiesByType( EntityPlayer )[0];
				if(axis=='x'){
					this.vel.x=-this.vel.x;
					other.vel.x=-other.vel.x;
					player.vel.x=-player.vel.x;
					this.vel.y=0;
					other.vel.y=0;
					player.vel.y=0;
				}
			}
		}

and some other varations of the same without any success any idea?

1 decade ago by Rapt

I just made a work around but I don't know if I'm doing it right and a new weird issue apperas, this is the code

		collideWith: function(other,axis){
			if(other.isBox){
				this.collides = ig.Entity.COLLIDES.FIXED;
			} else if(other.isChon){
				var boxes = ig.game.getEntitiesByType( EntityBox );
				this.collides = ig.Entity.COLLIDES.ACTIVE;
				for(var i=0;i<boxes.length;i++){
					if(this != boxes[i]){
						if(this.check(boxes[i])){
							this.collides = ig.Entity.COLLIDES.FIXED;
						}
					}
				}
			}
		},

but now when pushing two verticals boxes it works perfect, but when push horizontally some times one of the boxes just jump one tile up.

Any Idea on how to implement this 1 box movement and 2 boxes restriction?

1 decade ago by Rapt

Hi, anybody knows an answer for this?

1 decade ago by quidmonkey

.collideWith() is called after collision resolution. You may want to move your logic into .check() to change the collision type prior to collision resolution. You can also try to set this.pos.y = this.last.y to prevent the box from jumping up one tile.

1 decade ago by Rapt

check was ok, but the this.pos.x = this.last.x or y didn't work at all, as soon as the script is over for one frame, the pos.x or y is updated no matter what... what could be causing it?
Page 1 of 1
« first « previous next › last »