Actor movement behavior help

violaterr

  • Posts: 14
Hello all,

I am trying to complete a 2 way horizontal movement behavior which is supposed to function as follows:

on creation begin moving right, on touch flip the movement to left, another touch back to right, so on and so forth. I have this working.

My problem is I want the actor to move towards the center of the screen, and stay there, while the mouse is down. I almost have it but I must be doing something wrong because two bugs occur:

bug1 is if the actor moves all the way to the right side of the screen and then i hold down the mouse, he won't stop once reaching the center of the screen.

bug2 is if i test the game on my mobile device (android) the move to center while mouse is down and then stay there when centered block of code doesn't work at all.

Attached is my attempt at creating the behavior so far, perhaps you can see my mistake? Thanks in advance for any help anyone can provide me. I should mention the actor also has the cannot exit screen behavior enabled (only the x-axis)

letmethink

  • *
  • Posts: 2545
Your problem is that your character won't always land exactly on the center of the screen. It will pass it if moving at a fast/normal speed. You character's x could be less than center one frame and then more than center the next.
~Letmethink

violaterr

  • Posts: 14
Ok I'm glad you could confirm that which I was already thinking was the issue in my head. So I need to make the condition more forgiving with some sort of min-max values? Will this mean I will not be able to lock him in at the exact center?

letmethink

  • *
  • Posts: 2545
What you can do is check if his position is < the center and he is moving left or > the center and he is moving right and then set the x to the center in that situation.
~Letmethink

violaterr

  • Posts: 14
That worked wonderfully, great idea and thank you for your help.

The revised behavior for future seekers: