Jump to content

more "juicy" enemy movement


ageibert
 Share

Recommended Posts

first of all: i really like phaser! rarely seen such a clean and easy lib :)

 

i finished my first goal with setting up a tile map, player movement, shooting bullets, enemy movement - and collision.

 

the result can be seen here:

http://test.geibi.de/phaser

 

now i want to establish a more "juicy" or intelligent enemy movement. by now my enemies are moving somehow boring.

the code for the movement can be seen here:

https://github.com/geibi/phaser/blob/master/js/Actor.js

and here in the "move()" function

 

could anyone suggest a better movement method? maybe some sinus calculations or something else?

also sometimes the enemies "wiggle" for some milliseconds which is also not really nice.

 

and the code for the movement itself seems a bit circumstantial. but i don't have a clue how to make it better.

 

thanks a lot for any suggestion

 

edit: take care! if the player is in aggro range, enemies move towards him/her causing him/her loosing hitpoints. if the player dies you have to reload, because there's a bug on player death which causes javascript to quit 

Link to comment
Share on other sites

Two things that I noticed:

 

Enemies only adjust their movement-target when the player first comes into aggro range and then again after they collide with something.

I think they should always adjust their target as long as the player is in aggro range. this way they smoothly follow any moves the player makes.

 

The second thing is that you use moveToXY with a specified time. - This means, that if the enemy is close to the player when the target is recalculated it moves slow and if the player is further away it moves faster. (Since it want's to cover the distance in a constant time.) I think this makes enemy movement feel strange.

I would make sure to use a constant speed for the enemy movement. (just use moveToXY without the time parameter, then the speed given will not be modified)

Link to comment
Share on other sites

Hi jpdev,

these are really good points.

 

I would make sure to use a constant speed for the enemy movement. (just use moveToXY without the time parameter, then the speed given will not be modified)

 

Yes, the problem is, that i want different enemies moving at different speed. that's why i established the "movementTime" variable, but there's an error in it's calculation, because enemies move slower at small distances...

 

I think they should always adjust their target as long as the player is in aggro range. this way they smoothly follow any moves the player makes.

 

This is another problem i'm facing, but after your info and some rethinking i figured it out to move the enemies constantly if they got aggro now. Sadly i now got the same problem, that the enemies slow down the nearer they are to the player's position.

Enemies only adjust their movement-target when the player first comes into aggro range and then again after they collide with something.

And this is my biggest problem. I need to use "game.physics.arcade.moveToXY". Otherwise, e.g. with tweening, i don't get physics and enemies won't collide with walls.

This is explained here:
http://www.html5gamedevs.com/topic/10508-sprite-movement-movetoxy-vs-using-tween

With tweening, which i implemented before, enemies can easily change their direction because i got an "onComplete" event. However with moveToXY and don't have any chance to move to another direction because i don't know when the movement (former: the tween) is completed.

Here i'd need a much better way to determine the random movement, but that's exactly my point because i don't know how :)

 

 I updated the files and i think you have to reload your browser.

Link to comment
Share on other sites

To have enemies move at different speeds try to still ignore the "time" argument to moveToXY (skip it completely) instead just set a different speed (the argument before the time argument)

 

Manual:

 

moveToXY(displayObject, x, y, speedmaxTime) → {number}

If you specify a maxTime then it will adjust the speed.

 

Just don't specify one :)

Link to comment
Share on other sites

moveToXY(displayObject, x, y, speed, maxTime) → {number}

Oh this is great! Thanks a lot for that one, i read it completely wrong.

 

I uploaded a new version and this is so much better than the old one now.

But i feel the enemies could move even more intelligent. 

I you got any other ideas that would be great.

 

... and i fear that i must implement some sort of pathfinding because they get stuck on objects (the barrel/the skeleton) :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...