Move random distance on touch release

Hey all, I've been playing around with various ways to do this, but they all seem a little clunky.

I have an actor that and I can rotate left or right, but when I touch (release) the actor, I want it to travel a random distance based on its current angle. Once it reaches that distance, it needs to stop and then I want to be able to rotate it and then touch it again to move again.

Any suggestions on the easiest way to do this?

Thanks!

Comments

  • SocksSocks London, UK.Member Posts: 12,822

    This should do it (the expression box just says random(50,300))

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    How's this?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • zolnier@hotmail.comzolnier@hotmail.com Member, PRO Posts: 25

    Haha! Sometimes the simplest things are right in front of you! Thanks! Is there a way to check if the actor is moving so that nothing else can happen/interact with it until it has moved its full distance?

  • bjandthekatzbjandthekatz Orlando, FlMember Posts: 1,375

    @zolnier@hotmail.com said:
    Is there a way to check if the actor is moving

    Use the attribute self.motion.linearVelocity

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited May 2015

    @zolnier@hotmail.com said:
    Is there a way to check if the actor is moving so that nothing else can happen/interact with it until it has moved its full distance?

    That's what the first rule does. It checks to see if the actor's velocity is zero.

    Also, @Socks' use of a random distance is generally a better method than my random timer. Didn't see that when I posted my demo. ;)

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • zolnier@hotmail.comzolnier@hotmail.com Member, PRO Posts: 25

    I assume I can check for Linear velocity (x and y) being greater than zero.

  • SocksSocks London, UK.Member Posts: 12,822

    @zolnier@hotmail.com said:
    I assume I can check for Linear velocity (x and y) being greater than zero.

    Not quite, if an actor is moving from left to right (0°) at a speed of 300pps it will return (when checked) a linear velocity x value of 300 . . . . but if it were moving right to left (180°) at 300pps it will return a linear velocity x value of -300 . . . . so checking whether the linear velocity x value is greater than zero will give you a positive result for the left to right (0°) movement - and a negative value for the right to left (180°) movement.

    Or in other words, if you check whether linear velocity x is greater than zero to see whether it is moving, then all movement the opposite direction (even rapid movement) will register as not moving.

    You could try [not equal to], I think that should work fine.

  • zolnier@hotmail.comzolnier@hotmail.com Member, PRO Posts: 25

    Yup! Makes sense! Thanks for the great comments, everyone!

Sign In or Register to comment.