Motion?
eboy
Member Posts: 239
How could I set-up an up and down motion for an actor with a little rotation and randomness...Thanks.
Comments
In your scene, set up an actor called TOP that stretches across the top of the screen. This is the barrier that keeps the ball from going off the top.
Do the same with an actor called BOTTOM that stretches across the bottom of the screen.
In the code for the Moving Ball that I spawn, there are 2 "naked" behaviors and 3 rules. By "naked", I mean they're outside of any rules.
Behavior 1: Rotate. Set the rotation direction and speed.
Behavior 2: Change Velocity. Set the initial direction and speed, relative to the scene.
Now, you have it moving and rotating as soon as it's spawned.
Rule 3: When actor receives event Overlaps or Collides with actor of type TOP, Change Velocity to whatever direction and speed you want. I use relative to screen. Since you said you want to introduce some randomness, set the direction to random (0,180). Wait, that won't really do it. You want it to move "down", so try random (225,315), or whatever fits your need.
Rule 4: When actor receives event Overlaps or Collides with actor of type BOTTOM, Change velocity to direction random (45,135), or whatever fits, relative to screen.
Rule 5: When Any -- attribute self.Position.X <= 0 (if it goes off screen left) or attribute self.Position.X >=480, Destroy the actor.
Of course, you could also place two other actors LEFT and RIGHT on the scene, and code two additional rules for your actor to change its direction (using Change Velocity) and it would keep on bouncing until it ran into something that was designed to stop it. In that case, you'd replace the self.Position.X code with the appropriate Overlaps or Collides code to destroy the actor.
This worked for me. Hope it helps you.
Steve
1.
Plus, you can hover over the magnifying glass (like the one at the top of this page) and search for topics you're interested in learning more about in the Wiki, this Forum, etc. Very helpful feature. I learn something new every time I do a search.
Perhaps the best way to learn is to try it. If you're not sure how a particular behavior works, build a small example, compare it to a similar behavior, etc. If you're using an expression that doesn't seem to work, assign its value to a global variable (game attribute), then use Display Text to help you debug what's happening.
You'll get there... and soon you'll be answering questions for others on the forum!