Jump to content
Sign in to follow this  
Kubinna

Platform builder

Recommended Posts

Hello,

I am creating 2D mobile game, where will player create own platforms on which will be moved fluid. From testing I found, that in 3D I have better fluid physic and performace, so I decided create this game in 3D, but use camera in 2D view and I want use your asset to build platforms.

 

Platforms will be:

  1. Straight -> blocks
  2. Combined with other platforms -> no spaces between neighboring platforms
  3. Every platform could be erased
  4. Player will create platform from first click to mouse position or position where was released mouse button

 

Creating of platforms by player (own script):

  1. As first thing I am calculating angle between two points (first mouse button click and release button position or mouse position in drag)
  2. Via this angle I will calculate edge points by given height of block (for me in 2D it is width -> variable widthLine)
  3. Using function CreateShapeFromPolygon
  4. Platform is created
angleDeg = Mathf.Atan2(platform.secondPoint.x - platform.firstPoint.x, platform.secondPoint.y - platform.firstPoint.y);

points = new Vector3[4];
points[0] = new Vector3(platform.firstPoint.x + widthLine * Mathf.Cos(angleDeg), platform.firstPoint.y - widthLine * Mathf.Sin(angleDeg), 0f);


points[1] = new Vector3(platform.secondPoint.x + widthLine * Mathf.Cos(angleDeg), platform.secondPoint.y - widthLine * Mathf.Sin(angleDeg), 0f);

points[2] = new Vector3(platform.secondPoint.x - widthLine * Mathf.Cos(angleDeg), platform.secondPoint.y + widthLine * Mathf.Sin(angleDeg), 0f);

points[3] = new Vector3(platform.firstPoint.x - widthLine * Mathf.Cos(angleDeg), platform.firstPoint.y + widthLine * Mathf.Sin(angleDeg), 0f);

platformObject.GetComponent<pb_Object>().CreateShapeFromPolygon(points, m_Height, m_FlipNormals);

 

Combining of platforms:

  1. If player click on created platform from side where he clicked will be created another platform
  2. Not combine objects like this (on center -> use last point of created object):image.png.44ec4390ac8b7fdb0359d5e28d068fca.png
  3. Combine objects without any spaces like this:(because player can drag with second platform, it must be dynamic generated by mouse position)image.png.b7ce946e8c0ab98744c9551d519f5cef.png

 

Problems:

  1. Is there some chance how create this platforms easily than how I am creating them now? (point -> Creating of platforms by player (own script))
  2. Is there is some posibillity how combine objects without any spaces? I tried calculate it by angles and distances, but it is not precisely and very hard. Not solved yet by math. :(
  3. Is function CreateShapeFromPolygon good for use on this problem or is some better function?
  4. In combine of objects, objects can´t overlap, because in overlap area will be maybe another shade?
  5. If platforms will don´t have overlap areas, and one object will be erased, combined object must be edited to basic shape.

Thank you very much for your time and help! ;)

 

Share this post


Link to post
Share on other sites

Is there some chance how create this platforms easily than how I am creating them now? (point -> Creating of platforms by player (own script))

I don't think you'd need to use CreateShapeFromPolygon for this. Rather, just a series of quads would suffice.

Is there is some posibillity how combine objects without any spaces? I tried calculate it by angles and distances, but it is not precisely and very hard. Not solved yet by math. :(

Here's an article that you may find helpful. It should cover the math that you're looking for.

http://codeflow.org/entries/2012/aug/05/webgl-rendering-of-solid-trails/

Is function CreateShapeFromPolygon good for use on this problem or is some better function?

Probably just a series of quads is what I'd use. However I think your approach will also work.

In combine of objects, objects can´t overlap, because in overlap area will be maybe another shade?

Yes, so adjust your corner vertices to line up precisely with one another. See the article linked above.
 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×