Bounce around the screen

How can I make an actor bounce around the screen?
As an example - I want the actor to move right, while bouncing

Comments

  • SolarPepperStudiosSolarPepperStudios Member Posts: 754
    Turn bounciness to 1 and then in the actor say:
    - accelerate in direction 0 relative to scene at a speed of (whatever you want)
    Then in your scene make a floor so that the actor will collide with it (therefore making it bounce) and turn gravity on to about 250
    Then in your actor tell it to collide with the floor actor
  • godmoneygodmoney Member Posts: 11
    Thank you very much for your help.
    My problem is the global gravity parameter.
    I want a few different actors, all with different bouncing height.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2013
    You can set your own gravity for each actor using Accelerate direction 270 (relative to scene) at whatever speed you want.

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

  • godmoneygodmoney Member Posts: 11
    I uploaded a video demonstrating my problem. The bouncing looks weird and get stuck in wrong places.

    Here's the link:


    Here are the details:

    1. The scene has left boundary actor and right boundary
    2. The Ball actor has the following rules:
    2.1 When it hits the left or right boundaries it changes direction
    2.2. It collides (and bounces) with the floor, left boundary and right boundary
    2.3. It has Change Velocity rule of Speed 100 and the direction
    2.4 It has Accelerate with Direction 270 and Acceleration of 350
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    What rule/behaviors are you using for the "changes direction" part?

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

  • godmoneygodmoney Member Posts: 11
    I have an integer attribute called direction. 1 is right and 0 is left.
    When the ball collides with the left boundary it changes the direction to 1 and collision with the right boundary changes the direction to 0.
    Then, if Direction = 1 I change velocity to Direction 0 and Speed 100.
    Otherwise I change Direction to 180 and Speed 100.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2013
    Those rules will indeed change the direction but you're taking a ball that is bouncing up and to the right (for example) and making it bounce off at a right angle to the wall. That's not how a ball bounces... it bounces off the wall, goes up slightly, and then gravity brings it down. Similarly, a ball that bounces on its way down will not bounce off the wall perpendicular to the wall but will instead keep going down as it changes directions.

    If you use the ball's linear x and y to determine its directional path (I think you use vectorToAngle) you should be able to have it bounce off at a 90° angle to the path instead of just 0° or 180°.

    You may have to add or subtract 90° depending on how the ball is bouncing:

    image

    And I guess really that's a simplified way of thinking of it:

    image

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

  • godmoneygodmoney Member Posts: 11
    Wow - thank you very much for the very detailed explanation!
    Problem is - I'm not sure how to use it :)...

    What should I do with the linear x and y parameters?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2013
    Well, I worked out a formula that I think works for each case (ball travelling up-right, up-left, down-right, and down-left): 360-[path angle of ball] Hmm, no that's not it.

    The trick is to get the angle the ball is travelling. By linear x and y I meant self.motion.linear velocity.x (and y). The formula for the path angle of the ball is vectorToAngle(self.motion.linear velocity.x,I created a change attribute that sets self.image to main actor attack ( boolean attribute I created under "game").

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

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Here's an imperfect demo. There's probably an easier way to do all this!

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

  • godmoneygodmoney Member Posts: 11
    I need to add or subtract 90 according to the ball's direction (up or down). How do I know if it's moving up or down?
  • godmoneygodmoney Member Posts: 11
    Looks like just adding 90 works just fine... I think....
  • godmoneygodmoney Member Posts: 11
    And now it doesn't work... how weird...
  • godmoneygodmoney Member Posts: 11
    And it's getting even weirder... seems like what worked before, and works pretty good now is: vectorToAngle( self.Motion.Linear Velocity.X , self.Motion.Linear Velocity.Y (+90
    which looks like a mistake... but it works...
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    edited March 2013
    Trust the physics engine! Use collide behaviors (in the ball) for the floor and walls. Change the ball to circular collision shape. Work on bounciness, friction and drag (for walls, floor, and ball) until everything feels like it should.
Sign In or Register to comment.