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

7 years ago by ansimuz

I have some bouncing entities that I want to ignore the "one way slopes upward" and do a jump when they touch a solid collision tile. as show in this image

/><br />
<br />
My problem is that a few times the entity wont ignore the "one way slope" and make a jump over it as it were a solid tile.<br />
<br />
What could be missing? Is it an engine glitch or a bug in my code. Let me know your thoughts.<br />
<br />
Heres the code for the bouncing entity:<br />
<br />
<pre class= handleMovementTrace: function (res) { // passthrough one way solpes if (res.collision.slope && // slope collision? res.collision.slope.nx == 0 && // slope is one-way upwards? res.collision.slope.ny == -1 ) { // Pass through the walls // this.pos.x += this.vel.x * ig.system.tick; this.pos.y += this.vel.y * ig.system.tick; return; } if (res.collision.y && this.vel.y > 0) { this.vel.y = -this.speed; // bounce upward when it touches a solid tile } // I included the parent code instead of using call to the parent this.standing = false; // pasted the parent class code so the // bouncing forever works if (res.collision.x) { if (this.bounciness > 0 && Math.abs(this.vel.x) > this.minBounceVelocity) { this.vel.x *= -this.bounciness; } else { this.vel.x = 0; } } if (res.collision.slope) { var s = res.collision.slope; if (this.bounciness > 0) { var proj = this.vel.x * s.nx + this.vel.y * s.ny; this.vel.x = (this.vel.x - s.nx * proj * 2) * this.bounciness; this.vel.y = (this.vel.y - s.ny * proj * 2) * this.bounciness; } else { var lengthSquared = s.x * s.x + s.y * s.y; var dot = (this.vel.x * s.x + this.vel.y * s.y) / lengthSquared; this.vel.x = s.x * dot; this.vel.y = s.y * dot; var angle = Math.atan2(s.x, s.y); if (angle > this.slopeStanding.min && angle < this.slopeStanding.max) { this.standing = true; } } } this.pos = res.pos; },

7 years ago by Joncom

I've read your post several times, but I'm not quite sure what the behavior you're describing is supposed to look like. Would you mind posting a video of what's happening? And/or rephrase the behavior you're looking for?

7 years ago by Xander

I'll echo Joncom.

Are you saying you want your entity to ignore one way tiles entirely? But this isn't working?

Have you stepped through the code in real time in Chrome or anything?

7 years ago by ansimuz

Here's a video to illustrate what's going on.

https://cl.ly/1P203L09090N

The greenish platform is the oneway upward collision tile. For some reason it passes through and sometimes it bounces on it (as it were a solid tile).

Let me know.

7 years ago by ansimuz

Hey Xander,

Yes that's exactly what I want to acomplish. I have never "step through code" :(

7 years ago by ansimuz

It's weird I made a simple game with just the bouncing entity and it works Perfectly. Maybe I have an entity like the player that is causing the error.

7 years ago by stahlmanDesign

In my game I had a different player for walking and swimming. When the walking player touched a water tile, it would kill() the player and spawn a playerSwimming Entity. Here's how I detected the tile.

handleMovementTrace: function(res) {
			if (this.lifeTimer.delta() > 0.5){ // only check if should spawn other type of player if has existed for a bit, this avoids infinite back and forth
				var waterTile = 46; //46th tile on collision tiles changed to be water (by default it is empty)
				//if no collision with ground, wall or slope, then could be water // phase transition ensures it doesn't flip back and forth instantly in an endless loop
				var tileSize = 8;

				// toe about to step into water (collision tile 46) on next update?
				var toe = this.pos.y + this.size.y + 1;
				if (ig.game.collisionMap.getTile(this.pos.x + (this.flip ? +6 : this.size.x - 6), toe) == waterTile) {
					// if walking on an entity or near an edge, flip if more than 1 second since last flip
						var upOrDownPush = (this.vel.y >= 0 ? 50 : -150)
						//ig.show("udp=",upOrDownPush)
						this.kill();

						ig.game.spawnEntity(EntityPlayerSwimming, this.pos.x, this.pos.y, {
							flip: this.flip, vel:{y:upOrDownPush}, accel:{y:upOrDownPush}
						});

				}
			}

Maybe you could detect the one-way tile using this method and allow the creature to pass through.

7 years ago by ansimuz

Thank you Stahlman,

But is exactly woht this conditional should do:

 // passthrough one way solpes
                if (res.collision.slope && // slope collision?
                    res.collision.slope.nx == 0 && // slope is one-way upwards?
                    res.collision.slope.ny == -1 ) {
                    // Pass through the walls
                    //
                    this.pos.x += this.vel.x * ig.system.tick;
                    this.pos.y += this.vel.y * ig.system.tick;

                    return;
                }

It works by itself the issue should be hidden on other part in my game code.
Page 1 of 1
« first « previous next › last »