Jump to content

Change Direction of a Sprite on Collision


marros1812
 Share

Recommended Posts

I have my enemies and they will move and change direction on the x axis when they collide with a collision box. At the moment it has a walking animation but I want it to change to the opposite direction when it collides. My enemies are in a group and I can't figure out how to access them to change their individual properties when they collide with a box. Anu ideas?

 

 

Link to comment
Share on other sites

I managed to get this. I created a function that is called when an object in the enemies group collides with a collision box. I passed in the object from the collision and set  scale.x *= -1. Hope this helps anyone elese. The function I used liked like this

function changeDir(enemy) {	enemy.scale.x *= -1;						}

my enemies groups is called enemies.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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