How to make an actor follow another actor in a looping background?

Hello!
I'm new around here and I'm having a serious issue in my project.

I want to make an actor (a moth) follow another actor (light), which is the player's mouse. I've used the Constrain Attribute to place the light actor always in the position of the mouse. I've done the same thing in the moth actor, but only for the Y position (because I don't need it to overlap the light) and this actor also has the control camera attached.

So far it's working fine, the problem happens when the moth reaches the end of the screen shown by the camera. This is a side view game and the background continues beyond this camera, but since the mouse leaves the screen, I can't make the moth keep following the light.

Any ideas for this issue?
Thanks for any help :smile:

Best Answer

  • RThurmanRThurman Posts: 2,880
    Accepted Answer

    You might need to add the camera's origin to the coordinates.

    This is because the mouse position is given in screen coordinates. But you need scene coordinates. You can get the mouse's scene coordinates by adding the camera's origin to the mouse's screen coordinates.

    But there is a further complication. In order to get the camera's origin, you need to unlock the actors on the scene. Here is an example.

Answers

  • Nate_SNate_S Nate - Pixel Artist - Developer - Graphics Designer Member Posts: 86

    I'm not sure I completely understand the question. But from what I gathered you could theoretically have the mouse position Y contained to the actor Y. And for the X you could contrain the mouse X + 50(or any number) Pixels contrained to the actors X. Doing this would make the mouse never go off screen but the actor would always be at the edge of the screen or wherever you want it.

    Hope that helps, Sorry if that's not what you were asking.

    **Nate - Pixel Artist - Developer - Graphics Designer **

  • Karol_FlexKarol_Flex Member Posts: 4

    That's a good solution, thank you. But that way the actor following the mouse wouldn't be so natural... :confused:

  • Karol_FlexKarol_Flex Member Posts: 4
    edited June 2015

    Thank you RThurman, it's now working :smiley:

    I had to make a change in order to make it really work for me: in the moth actor, instead of a "move to" behavior I've used a "move", it wouldn't work otherwise.

    It still have some issues to fix, I would like if this actor wouldn't move backwards. I thought a simple restriction in the condition of the rule would work (something like "if mouse position x < actor position x") but it doesn't... :disappointed:

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

    @Karol_Flex said:
    It still have some issues to fix, I would like if this actor wouldn't move backwards. I thought a simple restriction in the condition of the rule would work (something like "if mouse position x < actor position x") but it doesn't... :disappointed:

    Perhaps its the camera origin issue again. Try something like;
    if (mouse position x + camera origin) > actor position x
    and see if that fixes the backward moving moth.

  • Karol_FlexKarol_Flex Member Posts: 4

    Thank's again RThurman :smile:

    I've resolved the problem with a simple collision actor placed in the back of the moth actor...

    The game it's finnaly finished!
    You can take a look here: http://arcade.gamesalad.com/games/131298

    I'm sorry, but it's written in portuguese :tongue:

Sign In or Register to comment.