Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to make a physical body flexible?
Started by peterbayrosh Jan 22 2020 12:19 PM

- - - - -
4 replies to this topic
corona sdk corona physics physics
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

peterbayrosh

[GLOBAL: userInfoPane.html]
peterbayrosh
  • Observer

  • 5 posts
  • Corona SDK

Hello crown lovers! My name is Peter. I have an idea to make grass that will sway in the wind. The Wind Simulator is easy to do:


require "math"
local physics = require( "physics" )
physics.start()
math.randomseed( os.time() )
 

function rt()
	local n = math.random( -1, 1 )
	if n==0 then
		n=n+1
	end
	print(n)
	physics.setGravity( n, 0 ) 
end

timer.performWithDelay(2500,rt, 0)





And now it remains to make a sprite "grass". Add to it the physical body and make it flexible. But I did not find the property flexible. I ask for help. I'll be glad!



[TOPIC: post.html]
#2

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 780 posts
  • Corona SDK

Try stacking progressively smaller circles on top of one another and attaching them with pivot joints.  You can adjust the flexibility with

joint.isLimitEnabled = true
joint:setRotationLimits( -10, 10) -- change it for each segment to make it move the way you like.

You can attach whatever image you want for each segment of the grass.

 

So you will have several images for each blade of grass underpinned with circle-based physics bodies that will react to the environment and bring the images along for the ride.

 

You can also have a go at it with mesh or path adjustment.



[TOPIC: post.html]
#3

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 780 posts
  • Corona SDK

You can also use the liquid fun particle engine and bind a stack of particles in a grass like shape and then give them properties to emulate swaying grass - I've done this to create gummy shapes that jiggle like jello, but there is probably a way to make them grass-like.



[TOPIC: post.html]
#4

XeduR @Spyric

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

  • 1,176 posts
  • Corona SDK

Sporkfin's suggestion of using joints is a viable one, but you could also consider "just faking it". For instance, you could have sprites of grass that shift in the wind. Then, as you adjust the wind, you'd simply rotate the sprites, or something along those lines.



[TOPIC: post.html]
#5

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 780 posts
  • Corona SDK

@Xedur, yes and if the grass is small enough you won't even have to adjust the physics body.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: corona sdk, corona physics, physics