Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Using polygon and collisions to mark boundary
Started by garyhenson Jan 15 2019 04:13 PM

2 replies to this topic
display point and click game
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

garyhenson

[GLOBAL: userInfoPane.html]
garyhenson
  • Observer

  • 12 posts
  • Corona SDK

Hello All!

I'm prototyping a Point and Click game, using it to learn the capabilities of the Corona SDK and what parts I need to make a PnC game.

I can load 'scene' images. I have a 'walking' sprite I borrowed and have coded the ability walk in all 8 directions depending on where you 'touch' the image.

Now I'm struggling a bit on setting/detecting boundaries to restrict where the sprite can go.

In PnC games you want the character to move to a 'touch' point unless there is something like a tree, or house or 'portal' to somewhere else. You also want to allow the character to walk 'behind' objects like trees and keep walking.

I thought I could add polygons (invisible) to restrict the movement using the physics engine. I made the sprite 'dynamic' with 'isFixedRotation' = true. I made the red polygon in the picture 'static'. I will adjust the right side of the polygon to be just to the left of the stairs on the image. The walker would be able to walk 'up/down' the stairs but when it reaches the polygon it stops automagically because of the engine. I would do the same on the right side of the stairs, but left that out for clarity now.

The problem I'm finding is that the boundary 'condition' is actually the vertical edge of the polygon that is 'most right', regardless of the rest of the polygon.

What I'm showing in the picture is that the sprite has 'hit' the polygons edge and will go no further.

So.

1. Is this approach valid/appropriate for boundary detection as I wish to use it?

2. What am I missing on the actual boundary exhibited by the polygon? 

Thanks for any help!

Gary

Attached Files



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 616 posts
  • Corona SDK

If I'm understanding you correctly, you are seeing that behaviour because of the physics engine's limitations. Box2d only deals with convex bodies with less than 9 sides, so when it encounters a corner with an internal angle larger than 180 degrees, it simply ignores it and jumps to the next vertex. You can see the actual shape by including the following line of code in your project: physics.setDrawMode( "hybrid" )

I've played a lot of point and click games and I don't think that you should use physics, especially for pathfinding. Your end results would most likely be clunky. Like I mentioned before, I would recommend going for something similar to the approach discussed here: https://www.groebelsloot.com/2015/12/24/pathfinding-part-1/
Alternatively, you could also consider using Jumper (https://github.com/Yonaba/Jumper).


  • garyhenson likes this

[TOPIC: post.html]
#3

garyhenson

[GLOBAL: userInfoPane.html]
garyhenson
  • Observer

  • 12 posts
  • Corona SDK

Thanks! I'm looking at Jumper now. It looks like a good choice to implement what I need.




[topic_controls]
[/topic_controls]