Collide and bounce with the scene border...

roxdesroxdes Member Posts: 4
edited November -1 in Working with GS (Mac)
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

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi Rox, welcome to the Forum; I'm relatively new here as well!
    roxdes said:
    I want my actor move randomly and bounce when it collide with the border of the scene.
    Thanks!!!
    Rox

    Possibly try making the border for collision with 2 actors, positioned to look like 1, then put collision detection for both in the bouncing actor's attributes. I think it should work then...

    :-)

    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

  • iPhoneDevForMeiPhoneDevForMe Member Posts: 362
    gyroscope has got the right idea!

    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
  • UPUP Member Posts: 70
    I haven't looked at the example, but do you really need 2 actors?
    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
  • iPhoneDevForMeiPhoneDevForMe Member Posts: 362
    lol yeah, you have to have 2 actors to reflect the X and the Y axis!

    -Kyle
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    ...as well as the fact that if you only have one graphic as a border, and the particular bouncing actor is in the middle of it, you wouldn't get any collision detection, as the player would be in the middle of it. By making the border out of two, to look like one, you've got outside surfaces for the border actors to react to.

    :-)

    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

  • UPUP Member Posts: 70
    Well… I just bounced my head against one wall only and you guys are right..
    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... :-)
  • roxdesroxdes Member Posts: 4
    Thanks guys! I add actors for the walls and it works just like I wanted !! :-)
  • JamesZeppelinJamesZeppelin Member Posts: 1,927
    iPhoneDevForMe said:
    Some stuff about bouncing

    Nice demo!

    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!
  • iPhoneDevForMeiPhoneDevForMe Member Posts: 362
    I'm glad everyone is finding good use of the info and demos! Just doing my part as a fellow GS developer!

    -Kyle
Sign In or Register to comment.