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 JackImpact

Hi All ImpactJS Stars,

I am developing a puzzle game in which players can splat pickles on the screen. The idea is that enemies will slow down when they hit the pickles on the screen and when they go through the pickle, their speed will resume. I managed to slow down the speed using check function but having a hair-pulling time with the speed resume. Cannt figure out why the check function is not working for me. Here is the code:
check:function(other){
				
				if(other instanceof EntityEnemy){
					
				
					if(this.touches(other)){
						other.vel.x=other.vel.x*0.99;
						other.vel.y=other.vel.y*0.99;
						}else{
							other.vel.x=90;
							other.vel.y=10;
							}
						
				
					
					}
				},

The code above can slow down the enemies but cann't reset the speed of enemies.

Your help is much appreciated and thanks heaps!

Cheers!

Jack

1 decade ago by StuartTresadern

I think I get what you are doing ! the reset will never get hit because the check will not fire when your entity is not in contact with the pickle.

You need to reset in maybe your update !

1 decade ago by JackImpact

Thank you very much StuartTresadern! That explains why it is not resetting.
But since the speed of the enemy and the position of pickles are all dynamic in the game( players have the control over where they splat pickles and speeds of enemies may vary), in update function, how can I track down the moment the enemy leaves the area accupied by pickles to reset the speed to the one before the enemy hit the pickle?

1 decade ago by zedd45

This is just a theory, but perhaps you could move your logic to the .collideWith method of your entity? I think Stuart is right either way; Seems like you're going to have to reset the velocity when they are not touching. You could also try a timer, but none of these seem ideal.

Perhaps even move the check method to a base class of the enemies? then you could extend that, check if other is an instance of pickle, and then the enemy would be responsible for restoring the speed when not touching....

Good luck!
Page 1 of 1
« first « previous next › last »