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 KenD

I have a parent class, EntityFriendly, that defines a very simple behavior for any descendant classes. In the parent's update() function, I simply set the x velocity to whatever value is set for this.speed. This parent class also has a bunch of other behavior that gets inherited, but this behavior is the only one that is not working consistently. If I have two entities of the same class, both inheriting from EntityFriendly, both with speed set to -100 in their class, only one of the instances will actually move.

		update: function() {
			this.vel.x = this.speed;
				
			this.parent();
		}

Where this.speed is set to 0 in the parent class, and -100 in the subclass. If I trace out this.speed and this.vel.x in either class, I can clearly see that this.vel.x is not being set in one of the instances.

This has really got me stumped. Any clues as to what could be going on here?

1 decade ago by KenD

I traced the problem back to the collision map, but I&039;m unable to actually fix it. I discovered that my entity's x velocity was being set back to 0 after #this.handleMovementTrace() in the entity.js&039;s #update() method. My game doesn't make any use of the collision map, though - all positions are calculated as needed, and most entities have a gravityFactor of 0. I tried overriding handleMovementTrace() in my entity class and just having it do nothing, but it still won't move. I tried removing the collision map from my level, but that screwed the whole level up (black screen.)

Why the heck is my entity stuck? The trace result shows the tile positions as x: 1, y: 0. Using the collision map&039;s #getTile() method, I see that tile is a 0, which is blank, right?

What&039;s really weird is, after overriding #handleMovementTrace(), if I check the entity&039;s #vel.x value before and after the this.parent() call in update() I can see that it's being set correctly and remains correct, yet the entity simply doesn't move. And to reiterate, other entities of this class, at different y positions, DO move as expected. I'm at a complete loss as to where to go from here.

1 decade ago by KenD

Aaaaaaaand of course the answer is right in the docs. Well, the fix is, anyway. I totally forgot that handleMovementTrace() is where the position is set. I was so focused on velocity, I neglected that property. Even though I was staring right at the entity.js source code. That's what happens when I go away for a long weekend, apparently.

I'm still confused as to why I can't remove the collision map without destroying my level, but I can live with this fix.
Page 1 of 1
« first « previous next › last »