GameSalad

Howdy, Stranger!

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

Two questions: Why do colliding actors overlap and why did actors scatter instead of stay aligned?

I created a simple scene with a large red square actor, called "Target," in the middle of the game. It's X and Y positions are constrained to the center of the screen, and it's rotation is fixed. The scene has gravity set to 100 in the X direction, but because this actor's X and Y positions are constrained, it doesn't move. I then created a second actor, a smaller white square, called "Projectile." The Target is set to collide with the Projectile. The Projectile is set to collide with the Target and also with itself. Both actors have Bounciness set to 0.

Now I have the game spawn a new instance of the Projectile every second from the right side of the game. The idea was to see what would happen as more and more Projectiles are spawned and collide with the Target, and also with each other. I expected the first Projectile to stop as it collided with the Target. Then I expected the 2nd Projectile to stop as it collided with the first Projectile, and on and on until a had a line of Projectiles piling up and extending off the right side of the screen.

It pretty much worked that way except that as more projectiles appeared, the one that was against the Target was pushed further and further INTO the Target, until the Projectiles had penetrated the Target to it's center. Only then did they become unaligned or unstable (somehow) and finally fly out of the Target and off the left side of the screen

My two questions are:
1. Why did the Projectiles penetrate the Target, rather than piling up against it? Density seems to have no effect on this behavior.
2. What finally caused the Projectiles to break formation and fly through the scene, when they should have just continued to pile up against the Target in a straight line forever?

And, yes, I am a noob. Thanks for putting up with me.

Comments

  • RThurmanRThurman Posts: 2,823Member, Sous Chef, PRO
    This is a function of the Box2D physics engine that GameSalad uses. It is a physics simulator -- not real physics.

    But it is simulating physics closer than you think!

    You have created a simulation of a planet (the target) that is floating in space and somehow defying the massive gravity of a black hole (gravity set to 100). In addition, the target is being bombarded with meteors (the projectiles) that are subject to the overwhelming force of the gravity of the black hole. And to top it off -- both the planet and the meteors mysteriously have a strong repelling force against each other (the collisions).

    You are seeing penetration because gravity trumps all other forces! (Its like asking why does a meteor embed itself into a planet instead of bouncing off?)

    You are seeing the meteors springing from the middle of the target because of the constant repelling force of the collision. (The closer it gets to the center of the target, the more the repelling force.)

    If the above analogy does not work for you. Then you might want to conceive of the simulation in terms of nuclear forces working on sub-atomic particles. (So, another way to think of the setup you have created is as a simulation of a nuclear particle accelerator.)

    Nice science project!
  • jamie_cjamie_c ImagineLabs.rocks Posts: 5,541Member
  • hamhosehamhose Posts: 12Member
    I agree - I like the visual of the black hole-like body in space. But .... that explanation got me thinking. I had gravity set to 100 in the X direction. What if I changed it to the Y direction and had the projectiles come from above? What if I further widened the Target to be as wide as the scene?

    Wouldn't this be like any game where you have a "floor" designed to stop an actor? That's what I thought. Nonetheless, the falling Projectiles still penetrated the Target, and eventually passed thru it to fall off the bottom of the screen.

    Here is where my Noob-i-ness comes in. The answer is that rather than un-checking the "Moveable" attribute of the Target, I instead added rules to constrain it's X and Y position. The Target was Moveable, but it's position was constrained. In my mind, a completely constrained position should be identical to having Moveable turned off. But they aren't the same.

    When I take away the Constrain X & Y rules, and instead just uncheck the Moveable attribute of the Target, there is no penetration or pass-thru. The Projectiles just land and stack themselves up in a straight line with no instability or any of the weird behavior before. So while I have answered my own question, it still leaves me wondering why a constrained actor can be overlapped, penetrated and passed through, while an unmovable one cannot.

  • RThurmanRThurman Posts: 2,823Member, Sous Chef, PRO
    As you see, changing "moveable" does more than simply constrain an actor to a certain x,y position. (Or is it less?) It essentially makes many of the physics interactions from Box2D inoperable.

    So what you have now is probably more like meteors that hit a surface that is defying the laws of physics. (That is, the target actor is no longer subject to gravity, and has infinite inertia.) In this case, Gamesalad (Box2D) will not treat interactions with the the target actor the same as it does with other 'more physical' actors. But at least the projectiles seem to be acting as you expect them to.

    It is interesting that you have to break physics to get the expected result.

    This often happens with games. In order to get the expected gameplay, one needs to break certain physics concepts. It happens all the time in cartoons and games. Game physics ≠ Newtonian physics.

    I would recommend that you break physics even further by not using gravity at all. Instead, give the projectile actor an acceleration behavior. Or even even better, I would recommend giving the projectile actor an initial change velocity. Most of the time projectiles don't actually accelerate -- they just get shot.
  • hamhosehamhose Posts: 12Member
    I gave your suggestion a try, but the most interesting results still occur using gravity on and constraining the position of the target. When I set the target to unmoveable I got the expected result - which I would describe as "Newtonian" behavior. The projectiles stopped at the target and just piled up in a straight line. But when I constrain the target, I get what I would call "quantum" behavior. The projectiles penetrate the surface of the target as if it wasn't solid, the pile of projectiles randomly breaks formation, and while most of the projectiles remain embedded in the target in a jumbled mess, a few manage to pass through the target and escape out the bottom - in Heisenberg uncertainty fashion. Ok, I realize I'm getting a little "out there" but you seem like someone who would appreciate the analogy.

    Back in the real world, however, the constrained target scene has developed an even weirder behavior. I have the projectiles set to spawn from the top of the screen, straight down the center. They are all spawned at exactly the same position. If the gravity is set to 10, the projectiles all "fall" from this location and then penetrate the target, etc. But, after about 1 minute, the projectiles no longer spawn at the hard-coded spot where they are supposed to. They still spawn from the top of the screen, at the expected Y value, but suddenly they start appearing at all different X values AND all different rotations. So a new random behavior kicks in after a minute.

    If I increase the gravity to 100, the projectiles strike the Target, penetrate it, start to pile up inside of it, and a few escape. But if you let the scene run, the pile eventually thins out as more and more projectiles pass thru the target. After a minute or two, new projectiles just pass right through the target as if it weren't there.

    I realize this has pretty much zero practical value in the world of game creation, and I am just screwing around, but this simple little scene has definitely been interesting to me.
  • RThurmanRThurman Posts: 2,823Member, Sous Chef, PRO
    Yes -- definitely got the analogy to quantum mechanics. You might want to pack these experiments away somewhere (for when you decide to do the ultimate particle accelerator simulation/game).

    Without checking (because its much more fun to talk), I'm guessing that the weird x-factor on the part of the particles might be due to them colliding when they are spawned. With gravity at 10 they don't accelerate much before the next one gets spawned. Are they colliding with the previous particles as soon as they are spawned. (Just speculation on my part.)

    I have no guess for why particles pass straight through the target (without stopping) after a few minutes. Chalk it up to Box2D physics!
Sign In or Register to comment.