Move random distance on touch release
zolnier@hotmail.com
Member, PRO Posts: 25
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
This should do it (the expression box just says random(50,300))
How's this?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
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?
Use the attribute self.motion.linearVelocity
Need Help? Email Me | Templates | Full Game Source Code
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
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.
Yup! Makes sense! Thanks for the great comments, everyone!