Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Programming a Puzzle to detect collision of other bricks, grid area etc.
Started by AngelaMcCall Dec 07 2019 03:37 PM

8 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

AngelaMcCall

[GLOBAL: userInfoPane.html]
AngelaMcCall
  • Enthusiast

  • 52 posts
  • Corona SDK

Hi all,

 

Please can you suggest the best way for me to handle the coding of this puzzle.
(See attached image)

Following the Getting Started tutorials, (specifically the code about how to drag the ship), I have successfully been able to code all the bricks and the key, to move/be dragged up and down or left and right on their respective paths.

Next I want to...

1) Prevent the bricks from exiting the grid area.
2) Prevent the bricks and the key from passing through each other.
3) When the player has fully slid the key out of the bottom of the grid area, I want the game to recognise that this event has occurred so I can add the key to the players inventory and mark the puzzle as completed.

Would all 3 things be a physics need?
I've not had any reason to use the physics engine before, so totally green to its capabilities.

Or is it a case of coding x/y coordinates and/or heights/widths etc??
Is it a maths thing?
 

If you could be so kind as to point me in the right direction, I am sure I can figure it out, its just knowing what I need to research or best practices in these situations which is all new to me.

Thanks in advance
Angela

 

Attached Files



[TOPIC: post.html]
#2

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 711 posts
  • Corona SDK

I think physics is the easiest solution.  Let the physics engine do the heavy lifting.



[TOPIC: post.html]
#3

AngelaMcCall

[GLOBAL: userInfoPane.html]
AngelaMcCall
  • Enthusiast

  • 52 posts
  • Corona SDK

Hi Sporkfin,

Thanks for sending me down the physics path.

 

I have created static walls, ceiling and ground.

 

My key and (only coded two) bricks are set as dynamic (will code others once I've got things working)

This is so that the key and bricks can collide with each other and the walls, ceiling, ground etc.

 

However, dynamic setting means that they can rotate, which I do not want them to do at all.

I want them to be set to their horizontal/vertical paths only.

Any ideas on how to code this?

 

Thanks again, this is completely new to me. 

Thanks

Angela

 

Attached Files



[TOPIC: post.html]
#4

AngelaMcCall

[GLOBAL: userInfoPane.html]
AngelaMcCall
  • Enthusiast

  • 52 posts
  • Corona SDK

I figured...
 

    itemKey.isFixedRotation = true -- locks against (prevents) rotation
 

and applied this setting after adding object to the physics body, so no rotation occurs, however, the object can still move left and right



[TOPIC: post.html]
#5

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,103 posts
  • Corona SDK

If you go the physics route, you'll probably also need to disable gravity and set which direction you can drag the objects (not actually a physics thing). Also, if I remember correctly, you'll also need to work with dynamic bodies for all those blocks (since iirc, only dynamic bodies can collide with other bodies).

 

I'd personally go for a logic based system and not physics, i.e. I'd write a function that checks which way each block can move and how far, and have it update whenever a block is moved. This method might be a bit more difficult though.

 

Still, I think both approaches should be fine, but each have their difficulties and potential issues. With physics, for instance, you need to prevent the player from being able to push blocks with other blocks or bump the key into locations it shouldn't go, etc. I personally don't favour physics for these kind of precision puzzles. Still, you should do what you feel works best for you.



[TOPIC: post.html]
#6

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 711 posts
  • Corona SDK

You can use logic checks with a touch joint before setting the object's new position.  object.setTarget( )



[TOPIC: post.html]
#7

AngelaMcCall

[GLOBAL: userInfoPane.html]
AngelaMcCall
  • Enthusiast

  • 52 posts
  • Corona SDK

If you go the physics route, you'll probably also need to disable gravity and set which direction you can drag the objects (not actually a physics thing). Also, if I remember correctly, you'll also need to work with dynamic bodies for all those blocks (since iirc, only dynamic bodies can collide with other bodies).

 

I'd personally go for a logic based system and not physics, i.e. I'd write a function that checks which way each block can move and how far, and have it update whenever a block is moved. This method might be a bit more difficult though.

 

Still, I think both approaches should be fine, but each have their difficulties and potential issues. With physics, for instance, you need to prevent the player from being able to push blocks with other blocks or bump the key into locations it shouldn't go, etc. I personally don't favour physics for these kind of precision puzzles. Still, you should do what you feel works best for you.

 

Hiya,

Thanks for replying, so using the physics route I have already disabled gravity and set the key and bricks to dynamic. I also learnt you can stope the bricks/key rotating, but they can still move in all directions. The key just pushes the bricks down. So the game knows the bricks have a body but I've been unable to restrict their axises.

 

I was trying to sleep last night and all I could think about was this damn puzzle!!LOL
So I kind of resided to the fact that I might have to go logic based and do the math.
 
But I am not sure on how to tackle it from this approach either.

THanks



[TOPIC: post.html]
#8

AngelaMcCall

[GLOBAL: userInfoPane.html]
AngelaMcCall
  • Enthusiast

  • 52 posts
  • Corona SDK

You can use logic checks with a touch joint before setting the object's new position.  object.setTarget( )

 

Ok, so before I scrap the physics approach Im going to research the touch joints. THanks



[TOPIC: post.html]
#9

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 711 posts
  • Corona SDK

You can also play around with the anchor points




[topic_controls]
[/topic_controls]