Collide and bounce with the scene border...
roxdes
Member Posts: 4
Hi,
I'm new here and my english is not very good so I will try to explain my problem the best I can... :-)
I want my actor move randomly and bounce when it collide with the border of the scene.
I use the velocity attribute, with a random direction, but my actor disappear ! :-(
Do you have ideas??
Thanks!!!
Rox
I'm new here and my english is not very good so I will try to explain my problem the best I can... :-)
I want my actor move randomly and bounce when it collide with the border of the scene.
I use the velocity attribute, with a random direction, but my actor disappear ! :-(
Do you have ideas??
Thanks!!!
Rox
Comments
:-)
PS You're English is just fine!
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Basically you will create 2 new actors, one for vertical walls, the other for the horizontal walls.
Drag each actor to the scene so that their edge match up against the edge of the screen. Use the vertical wall actor for the left and right side, and then use the horizontal wall actor for the top and bottom sides.
Now in your actor that you want to move around, drag the behavior "Change Velocity" and set it to random(0,360) using the expression editor (the "e" next to the text box). This will make the ball go in a random direction.
Now create 2 rules as follows:
When actor overlaps or collides with actor of type vertical wall
--Change attribute self.motion.linear velocity.x to -self.motion.linear velocity.x
When actor overlaps or collides with actor of type horizontal wall
--Change attribute self.motion.linear velocity.y to -self.motion.linear velocity.y
Pretty much change the x velocity to the negative of the x velocity when colliding with the left or right side and change the y velocity to the negative of the y velocity when colliding with the top or bottom.
Here is a link to a demo of mine that does this exactly:
http://gamesalad.com/game/play/59476
Download that and take a look if you are having problems! Hope this helps!
-Kyle
If using 1 only the object would not reflect correctly or?
Actually I was setting up a scene the other day using only 1 actor for the 'walls'
and the actor reflecting from it would not use the correct angle when bouncing off...
(it would only bounce on the X axis)
I guess I might just have answered my own question.. or.. ?? :-P
-Kyle
:-)
PS ...I think. ;-)
PPs Yet another neat demo by you, Kyle: http://gamesalad.com/game/play/59476
I'll download that as well, thanks!
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
it does not bounce off the expected direction... What was I thinking..??!!
With still a slight doubt in my mind I will now try where 2 walls meet at a 90° corner
at medium speed... bear with me... :-)
I really needed that.
I was actually working with something like this and i was trying to come up with a good way to keep the ball from getting stuck and just bouncing the same angle over and over.
Thanks!
-Kyle