Move one actor towards the direction of another actor.

I have a simple problem I can't solve. I am making my first game so any input would be great!

Say I have an actor on screen called 'A' and another actor that enters the screen called 'B'.

Right now I have got my game to the point B comes onto the screen at a slow speed and direction of 180 but once it hits a x coordinate (460) the speed increases and Actor B then moves towards a random direction. This actor then goes off screen and a new actor is spawned.

I want it so instead of B firing towards a random x and y coordinate, I want B to fire towards actor A so basically instead of specifying random coordinates I want the exact coordinates of actor A to be the direction B moves.

Now Actor A is movable therefore the co-ordinates will change with each new spawned actor. So I want somehow to know the position of Actor A when Actor B is a x coordinate 460 and then to move towards that direction.

Does anybody know how to do this?

Thanks in advance.

Comments

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    edited March 2014
    Use two Constrain Attributes on Actor A that keep track of it's X and Y locations. Something like:

    Constrain actorAX to self.position.x
    Constrain actorAY to self.position.y

    Now in actor B add Move To Behaviors set up to Move To the new actorAX and actorAY Attributes. They should be Game Level Attributes
  • FlowFlow Member Posts: 2
    Thanks for the comment,

    I made a global attribute, and used this to constrain the x and y position of actor A. I then told actor B to move to the constrained positions.

    This resulted in actor b moving to and stopping at the position of actor A, and if actor A moved around so did actor B to follow actor A.

    What I'm trying to do is, when actor b gets to self position of (less than) 460 on the x-coordinates, for it to move straight in the direction of where actor A was at that exact point.

    1) Now Actor A will move so I don't want Actor B to follow the movement path.
    2) I also don't want actor B to stop where actor A was but carry on (in a straight line) out of the scene.

    It seems to be more complex than I thought but if there is an easy solution please do let me know. Otherwise, not to worry as I can change the aim of my game to something a little more simple.
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    Hi Flow, it's not that complex so I'm sure you can get it working. Just think about what we have done so far and how you might adjust your behaviors to make it work exactly like you described.

    So for example you could say:

    When Actor B's X location is <460 move to Actor A's location

    When Actor B collides with Actor A move it out of the scene as you see fit.

    You pretty much have it described above. :)
Sign In or Register to comment.