Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Add physics to a drawn line
Started by sirmania Nov 01 2018 11:46 AM

14 replies to this topic
physics draw line happy glass
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

sirmania

[GLOBAL: userInfoPane.html]
sirmania
  • Contributor

  • 150 posts
  • Corona SDK

Hi fellow coders!

 

I am sure I have seen a video where someone was showing that they drew a line on the screen and added physics to it after the line was drawn, and the line fell down (like in the game Happy Glass).

I am sure it was a made in Corona. 

I can't find that video and I am starting to think it was a dream.

 

Please help  :(



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,286 posts
  • Corona SDK

In the old days, it was not a good idea to try to add physics bodies to lines.

 

Today, we have a toy in our toybox that lets us create line bodies:

https://docs.coronalabs.com/guide/physics/physicsBodies/index.html#edge-shape-chain-body

 

I can't recall right now, but you may need to do an offset calculation to match the line vertices with the chain vertices (or vice versa).


  • sirmania likes this

[TOPIC: post.html]
#3

sirmania

[GLOBAL: userInfoPane.html]
sirmania
  • Contributor

  • 150 posts
  • Corona SDK

Thanks!

 

"You should not construct an edge shape body with self-intersecting segments — in other words, your definition of vertices should not result in any segments of the chain intersecting with other segments. Doing so many break the expected collision detection of the shape."

That is a problem as I was hoping to be able to allow all kinds of drawings.

 

Could it be done by drawing the line using small circles, add physics to them and weld them together, or would it be to much for the device to handle if the line is long.

 

I used to play Plasma Pig That game was made with Corona. I wonder how he did it?

 



[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,286 posts
  • Corona SDK

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/11/draw_physics_line.zip

 

Yes, I noticed the body doesn't rotate... not sure why.



[TOPIC: post.html]
#5

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,286 posts
  • Corona SDK

re: intersections, perhaps just make it a multibody with chain shapes split at each intersection?



[TOPIC: post.html]
#6

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,286 posts
  • Corona SDK

re: plasma pig

 

1. I didnt' see any intersections.

 

2. You could do that with a series of tiny static rectangular bodies aligned to the line at that position.

 

i.e. the body has no line.  you create a bunch of tiny transparent rectangles tracing the line shape with bodies. 4..10 per line would do.



[TOPIC: post.html]
#7

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,286 posts
  • Corona SDK

You could do that with a series of tiny static rectangular bodies aligned to the line at that position.
 
i.e. the body has no line.  you create a bunch of tiny transparent rectangles tracing the line shape with bodies. 4..10 per line would do.


Yeah, I'm pretty sure that is how he did it:

 

see_segments.png



[TOPIC: post.html]
#8

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,286 posts
  • Corona SDK

Having the line fall would be a different trick. As you suggested you might consider connecting the objects together using joints.

 

I would not use a series of joints.  I'd connect all bodies to a single point on one object.

 

B-->A

C-->A

D-->A

...

Z-->A



[TOPIC: post.html]
#9

sirmania

[GLOBAL: userInfoPane.html]
sirmania
  • Contributor

  • 150 posts
  • Corona SDK

Yeah it seems like it.

Not perfect, but that would be ok in a children's game.
Plasma Pig is gone unfortunately (I really liked it), but I can't remember if lines could intersect in that game.

 

Your test looked great by the way, except for the not rotating part :)



[TOPIC: post.html]
#10

sirmania

[GLOBAL: userInfoPane.html]
sirmania
  • Contributor

  • 150 posts
  • Corona SDK

Thanks for the tip about the joints :)



[TOPIC: post.html]
#11

sirmania

[GLOBAL: userInfoPane.html]
sirmania
  • Contributor

  • 150 posts
  • Corona SDK

Blah!
Seems like using multiple weld joints makes the physics bodies scatter like crazy. It works when I draw a super short line, but not more.

 

Another thing is that for some reason I can't seem to get the circles to create with the same distance (circleradius*=0.5). The faster I move the finger the more scattered the circles.



[TOPIC: post.html]
#12

davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
  • Corona Geek

  • 1,236 posts
  • Enterprise

kinematic rects (act static for as long as need, then give velocity to simulate fall)

no chains, welds, multi-element bodies,..



[TOPIC: post.html]
#13

sirmania

[GLOBAL: userInfoPane.html]
sirmania
  • Contributor

  • 150 posts
  • Corona SDK

Hmmm....that is clever. It could work. 



[TOPIC: post.html]
#14

maximo97

[GLOBAL: userInfoPane.html]
maximo97
  • Contributor

  • 219 posts
  • Corona SDK

@sirmania

The project you are looking for is called "Crayon Physics". Creates a single multi-element physical body for each line fragment. As @davebollinger suggested.

 

I share a copy of code that I DID NOT DO but I can not find the author online:Attached File  CrayonPhysics.zip   11.81KB   3 downloads

 

However, I remember that the file had no restrictions.

 

I'm glad when someone here helps me, and I'm glad to reciprocate.

 

I hope it help.


  • roaminggamer likes this

[TOPIC: post.html]
#15

sirmania

[GLOBAL: userInfoPane.html]
sirmania
  • Contributor

  • 150 posts
  • Corona SDK

Million thanks, @maximo97  :D

 

This is exactly what I was thinking about. And to get access to the code is just amazing.

I have been spending a lot of time figuring this out, but I realized it was just to complicated for me.

 

Now we can focus on the game, finally  B)


  • maximo97 likes this


[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: physics, draw, line, happy, glass