Patrolling issue

AssortDisAssortDis Member, PRO Posts: 22
edited February 2015 in Working with GS (PC)

Hi,

I need an actor to move back left or right when it reach the end of screen with the following rules but for some reason, it just stop when reach the end of screen without going back.

Move in direction 0 at speed 300

Rule
     If self.position.x >= game.displaysize.width, move in direction 180 at speed of 300

Rule
     If self.position.x <= game.displaysize.width, move in direction 0 at speed of 300

Thanks in advance.

Best Answers

  • SocksSocks London, UK.Posts: 12,822
    edited February 2015 Accepted Answer

    @AssortDis said:

    Try this:

    constrain self.position.X to:

    (( game.Display Size.Width /2)- self.Size.Width /2) *sin( game.Time *100)+ ( game.Display Size.Width /2)

  • SocksSocks London, UK.Posts: 12,822
    edited February 2015 Accepted Answer

    @AssortDis said:
    I'll need some time to figure out how exactly that formula works though ^^

    (( game.Display Size.Width /2)- self.Size.Width /2) *sin( game.Time *100)+ ( game.Display Size.Width /2)

    Range of movement / distance (as a radius from the centre point)
    Speed
    Centre point of movement

Answers

  • AssortDisAssortDis Member, PRO Posts: 22

    @Socks
    Thanks a lot, this gives a pretty great result without adding too many rules.

    I'll need some time to figure out how exactly that formula works though ^^

Sign In or Register to comment.