Ennemy changes direction after a collision

Hello,

I am doing a project, and I have an issue.

I want an actor to change its direction after collinding with a wall. The ennely is moving alone, with a behaviour move.

When it collides the wall, I want it to move in the opposite direction. So I did like that :

When self.position.X < 2000
Actor moves right

And :

When self.position.X > 2450
Actor moves left

But after being < 2000, my actor does not go to right, just the animation works.

Can you help me please ?

Comments

  • silviossilvios Member Posts: 29
  • silviossilvios Member Posts: 29
    The thing I want to do :

    Like in this video (1:21), having an ennemy that walks alone and change direction after colliding with a wall :
  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2013


    But after being < 2000, my actor does not go to right . . .

    That is working as it should, your rule . . . .

    When self.position.X < 2000 / Actor moves right

    . . . says when the actor's position is less than 2,000 then the actor should move right, so when it eventually gets to 2,000 its value is no longer less than 2,000 so will no longer be subject to the rule that tells it to move right . . . . so it stops.
  • mystic 2628mystic 2628 Member Posts: 45
    edited December 2013
    I'm not fully sure about this, but couldn't you place a rule on the enemy that says: If actor overlaps or collides with Wall, move right? There is a condition for collisions that allows you to use a behaviour if an actor collides with another.
  • mystic 2628mystic 2628 Member Posts: 45
    If you want the actor to move before he collides with the wall, you'll have to use the magnitude function in the expression editor to keep track of the distance between the actor and the wall.
  • silviossilvios Member Posts: 29
    Thank you.

    Socks : Indeed, it is logical. So how I should do that ?

    Mystic : yes I want it to move before he collides with the wall. How can I do with the magnitude function ? I do not know that thing :/
  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2013
    @silvios

    Rule:
    When x position is equal to or greater than 2450:
    Interpolate x position to 2000

    Rule:
    When x position is equal to or smaller than 2000:
    Interpolate x position to 2450


    example: https://www.mediafire.com/?4xrckmkrl8boq34
  • silviossilvios Member Posts: 29
    It works ! Thank you so much !
Sign In or Register to comment.