Causing different results depending on where object is hit?

  • I am creating a game where a small bottle is hit by a ball. I would like to have the game cause the bottle to fall to the left if the ball hits the bottle on the right-hand side.

    Likewise, I would like to have the game cause the Bottle to fall to the right if the ball hits the bottle on the left-hand side.

    I cannot seem to figure out how to do this. Basically, the bottle is a single object. The best I could do is is cause a physics force when the bottle is hit. I likewise can have the game create a random physics force when the ball hits the bottle. I accomplish this by having construct look for the following event:

    Ball is overlapping bottle <-- but I cannot figure out how to have the computer determine if the ball is overlapping the left side of the bottle or the right side of the bottle. Again, the bottle is a single object.

    However, I cannot figure out how to instruct the game to apply a different physics force depending on whether the bottle was hit either on the left side or the right side.

    Anybody have any simple ideas how to do this? Thank you in advance.

  • PS: The only solution I have come up with so far is to create a left side Sprite and the right side Sprite and then pin those sprites onto the bottle object. Then what I do is I have a command that tells the computer to have the bottle fall left if the left side Sprite is hit and to fall right if the right side Sprite is hit. I also make both the left side Sprite in the right side Sprite invisible so that the person only really sees the bottle.

    The problem with this solution, however,is that once any bottle is hit, that causes every single bottle on the screen to be identically hit. Therefore, what this means is that I would be required to create a DIFFERENT left side Sprite and a right side Sprite for each and every single DIFFERENT bottle. that seems insane.

    I am hoping there is a far easier solution.

  • You have to "pick" the instance of the bottle you want it to affect via event conditions.

    Ie. put condition Ball-Isoverlapping-Bottle_instance as a condition in the event that handles the bottle stuff. This will tell construct ignore all bottles that aren't being overlapped by ball sprite and only affect the one that is...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • your solution did prevent all of the other bottles from falling over. Thank you very much.

    However, it appears that I am again stuck creating different left and right Side sprites for each bottle. For example, in my game I have two identical bottles. I simply copied and pasted the bottle so they are identical. However, when I pinned the left side Sprite and right side Sprite on one of the bottles, it does not apply to all the bottles. I also tried to copy and paste the left side Sprite and right side Sprite onto the second bottle. However, all of those left side and right side sprites appear to all be linked to the single first bottle.

    Therefore, it looks like I am still trying to find a solution (or should I say a much simpler solution), to allow all of the bottles on the screen to fall left or right depending on where the ball hit it without having the necessity to create independent left and right sprites for each different bottle that I then am stuck pinning onto each independent bottle. Hopefully that makes a little sense.

  • well, I cannot believe it, but I may have possibly come up with a simple solution. I am attaching a screenshot. Basically,assuming I understand what the hell I did correctly, I put the image point in the center of the bottle. Generally, that is where it goes anyway.

    Then what I did is I told construct that if the balls X point is less than the X point of the bottle, then the bottle should fall over in one direction using physics force. In the alternative I told construct that if the balls X point is greater than the X point of the bottle, then the bottle should fall over in the other direction using physics force. Candidly, I'm not sure what I just said so let me show you a screenshot. It appears to be working.

  • Nice, wish I had of thought of that when making my top scroll racing tutorial.. it uses the pinned left/right sprites as well to detect collisions with other racers to force player to side of road. Your new way is much more elegant and will allow Y as well for 4-point collision testing.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)