Making actor face target (homing target)

AlanoAlano Member, PRO Posts: 70

Hey all, so I have "enemy" actors homing in on my hero actor (think swarming bees). Right it's just blocks but when I added a graphic I see the enemy actor stuck facing to the right and NOT facing the target Hero actor they are moving towards. Example, when a missile shoots up in the sky and then falls down the nose cone always faces forward. In my case the enemies are traveling in from various directions and not just right to left, up to down.

Q: I know this is basic but how do I get the my actors to face the direct they are moving.

Thanks for the help!
Alan

Comments

  • colandercolander Member Posts: 1,610

    I am just taking a stab as I haven't tried to do this. Create two game level attributes and constrain them to the X and Y position coordinates in the Hero actor. Then use these attributes and the Rotate to Position behaviour in the enemy actor and see if you can get that to work.

  • AlanoAlano Member, PRO Posts: 70

    Hey thanks Colander. Unfortunately I'm still kinda new to GS. Do you mean to set "self.position.X and self.position.Y?"

    -Alan

  • colandercolander Member Posts: 1,610

    Yes create your Game level attribute of type Real (i.e. "heroPosX" or whatever you want to call it) and in the Hero actor, use Constrain and "game.heroPosX To self.Position.X"

  • AlanoAlano Member, PRO Posts: 70

    Hey thanks Colander!
    So I created that but no change. Perhaps I need a different tweak. More description of what I have:

    • I have a hero actor moving vertically up.
    • I have enemy actors attacking from the left and right sides. I have a Spawner set to random spawn.
    • As the enemies spawn and move towards the hero actor.
    • The issue is that the enemies coming from the right are normal facing. The enemies coming from the left are facing backwards. They are attacking BUTT first.

    Any advice would be greatly appreciated!
    -Alan

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Try this in the spawned enemy actors:

    When self.Position.X > hero.X
        Change Attribute: self.Graphics.Flip Horizontally To: true
    otherwise
        Change Attribute: self.Graphics.Flip Horizontally To: false
    
Sign In or Register to comment.