GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Simulate Bouncing

stan_mcginnisstan_mcginnis Posts: 15Member, BASIC

I have learned from a different discussion that you cannot get a very slow actor to bounce due to a Box2d rule, but is there any way to simulate bouncing using a rule? Maybe something using sin? Thanks!

Comments

  • tatiangtatiang Posts: 11,525Member, Sous Chef, PRO, Senior Sous-Chef

    I Googled bounce sin gamesalad and one of the top results was this:

    https://forums.gamesalad.com/discussion/comment/579115/#Comment_579115

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

  • stan_mcginnisstan_mcginnis Posts: 15Member, BASIC

    This would work for up and down bouncing, but my actor is on a flat plane where there is no gravity and it can move any direction and bounce off any wall. Also, this actor just bounces around and cannot be controlled by the player. Most importantly, the velocity should stay the same the whole time, like in a pong game.

  • tatiangtatiang Posts: 11,525Member, Sous Chef, PRO, Senior Sous-Chef
    edited November 27

    I'm no expert on GameSalad physics but I have coded a game where the actor reflects off of a wall to simulate a bounce, as you describe. I can't recall exactly how I did it (it was years ago) but I definitely used trig functions to calculate the reflection path based on the vector (direction) of the actor.

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

  • RThurmanRThurman Posts: 2,807Member, Sous Chef, PRO

    If the actor collides with a vertical wall, multiply its xVelocity by -1.

    If the actor collides with a horizontal wall (a floor or ceiling), multiply its yVelocity by -1.

  • stan_mcginnisstan_mcginnis Posts: 15Member, BASIC

    Does this mean I have to make a seperate actor for walls and ceiling? I am willing do that if that is the only way.

  • RThurmanRThurman Posts: 2,807Member, Sous Chef, PRO

    Yes, thats probably the most straight forward way to do it.

    I suppose that if you know the boundaries, you can skip checking for collisions with actors. Instead you could just test for the actor's x,y position.

    When (self.position.x < 0) or (self.position.x > 1024) then multiply xVelocity by -1.

    When (self.position.y < 0) or (self.position.y > 768) then multiply yVelocity by -1.

  • stan_mcginnisstan_mcginnis Posts: 15Member, BASIC

    Thanks! The walls are not near the boundaries of the screen though so I will have to use your previous idea.

  • RThurmanRThurman Posts: 2,807Member, Sous Chef, PRO

    You are welcome! Glad it will help.

    By the way, you can still use the x,y position method even if the "bounce" boundaries are nowhere near the screen edge.

  • stan_mcginnisstan_mcginnis Posts: 15Member, BASIC

    Lots of levels are like a maze, there are walls everywhere so using the x,y position method would take forever, but implementing a vertical wall and a horizontal wall was not as hard as I thought.

  • RThurmanRThurman Posts: 2,807Member, Sous Chef, PRO

    Great! Glad its working like you want.

  • stan_mcginnisstan_mcginnis Posts: 15Member, BASIC

    However, there is one problem: corners. When the object hits a sharp corner, only one of the directional velocities is changed, and the bounce is not natural. Is there any way to fix this?

  • RThurmanRThurman Posts: 2,807Member, Sous Chef, PRO

    Hmmm.... not sure what might be happening. Its almost impossible for the actor to hit both edges at the exact same instant -- so its unlikely to be that.

    What does "the bounce is not natural" mean? Can you give more detail?

Sign In or Register to comment.