Sign in to follow this  

Creating an "intelligent" enemy

Recommended Posts

Hi all!

I´m trying to get an enemy who flees from the player. But I have no idea how to get him jump.

The following code makes that he ran and stop on an hindernis. But he don´t want to jump... Any ideas? = {	preload: function(){		console.log("loading play state");	},		create: function(){		console.log("starting play state"); = mt.create("bg");		this.unten = mt.create("unten");		this.wolf = mt.create("wolf");		this.schaaf = mt.create("schaaf");		this.hindernis = mt.create("hindernis");		//this.points = mt.create("points");				this.cursors =;;	},		update: function(){, this.unten);, this.hindernis);, this.unten);, this.hindernis);				if (this.cursors.left.isDown) {        	this.wolf.body.velocity.x = -200;		} else if (this.cursors.right.isDown) {			this.wolf.body.velocity.x = 200;		} else {			this.wolf.body.velocity.x = 0;		} if (this.cursors.up.isDown) {			this.wolf.body.velocity.y = -300;		}								if(, this.hindernis) < 50){		   console.log("hüpf!");		   this.schaafJump();		   this.schaaf.body.velocity.x = 180;		}else{		   this.schaaf.body.velocity.x = 180;		}	},		schaafJump: function(){		this.schaaf.body.velocity.x = 0;		this.schaaf.body.velocity.y = -100;	}};

Share this post

Link to post
Share on other sites

The easiest way is to check for a collision with the hindernis object and then call the jump method.  You can change:, this.hindernis);

to:, this.hindernis, function(schaaf, hindernis){     schaaf.body.velocity.x = 0;     schaaf.body.velocity.y = -100;});

This should work.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.