Introduce an interactive grass system!

looks beautiful, as @AirWward said, it remembers me of some games, that grass remembered me of The Last Of Us: Part 2. Nice job

2 Likes

Any update on whether you will release this? Rlly need smth like this for a game :wink:

3 Likes

Well done! I would jump on this plugin in a heartbeat

3 Likes

Dang, touching grass to a whole new level. Has this been released yet?

3 Likes

Now I want make something like this myself… (I will try make it!)

3 Likes

Question as a fellow dev! How did you manage the touch connection? I know .touched is a poor solution to detection, so I’m curious as to how you went about determining when the player is touching the individual blades of grass?

2 Likes

I think it will depend on how you want to handle this and how many blades of grass you had.

For fewer blades

I would use math and calculate the magnitude distance from each grass blade. This would also allow you to create more or less bend the closer you get.

I had a stab at doing this with just blocks, and achieved the following:

I did this by:

  1. This loops through the grass in a grassfolder (which took 0.007927700004074723 seconds for 2048 parts) to store the original CFrame as an attribute.
  2. Connecting a runservice which then checks for a desired interval (so it only runs the code in it once every 0.1 seconds - this is better than using a while loop with task.wait()).
  3. Looping through all the parts in the grass folder.
  4. In each loop, it then checks the magnitude between the player and the part, calculates a new CFrame depending whether you are within the set distance or not.

It was a total 41 lines of code.

For unlimited blades

For very high numbers, you might want to use the touched event instead. This wouldn’t allow you to control the bend beyond just moving when you touch it (rather than bending as you get close).

However, an alternative would be to group grass togther in models, and do the same as the first option, but first check the distance between player and model, and only run the checks on individual blades if the whole group is within a certain distance, which would optimise it for performance.

Given I’ve spent some time work this all out I may implement this in my own game :stuck_out_tongue:

9 Likes

And here’s a version which uses a plane meshpart with a surface appearance on (grouped in models so that only close groups of grass is calculated).

I’ve mixed it in with roblox terrain and grass so you can see how it might look if you used in conjunction.

15 Likes

TSYM bro gonna have to put the work in for this.

2 Likes

Just wanted to say that I am still amazed by this

I tried to do it myself for weeks but I failed (I build but 0 scripting knowledge, had to try :pensive:)

2 Likes

Absolutely revolutionary. I need this.

3 Likes

Would love it if you made this open source :smiley:

3 Likes

Here you all are - I’ve commented throughout the code so you can understand what it’s doing, and if you want to change the values.

I’ve also included settings so you can switch between:

  • tween or LERP
  • updates every frame or after X seconds

If you’re looking for high end devices I recommend running the code as is. If you want it to work for lower-end devices, enable desired interval and/or switch to LERP.

InteractiveGrass.rbxl (513.7 KB)

15 Likes

I actually really appreciate you for making this, I didn’t think grass would be so interesting

2 Likes

Of all the grass, this is certainly one of them :crazy_face:

This is really cool! I’ll have to look at it later. Your optimization scheme sounds interesting. Great work!

1 Like

Thanks! I will have to try this out later, the OP mentioned possibly making a plugin for their grass but i guess not.

1 Like

so where’s the model download?

1 Like

looks better than any roblox grass ive ever seen, same for the interactions. thank you so much.

3 Likes

I’m going to give other noobs a small heads up about this script. I hope i can spare other people some frustration.

If you’ve got a lot of other stuff in the game, the setup part of the script may run before the blades of grass are loaded, which means their attributes wont be set and the script wont work.

two ways to combat this:

  1. add the loop and wait for every descendant of the grassfolder to the top of your setup() function. I think thats performant and wont be a problem but if anyone knows better then please correct me. I’ve not noticed problems.
local function setup()
	local grasstoload = grassfolder:GetDescendants()
	for _,v in pairs(grasstoload) do
		repeat wait() until v
	end
	
	for key, grass in grassfolder:GetDescendants() do -- get the descendants of grassfolder and call them grass
			if grass:IsA("MeshPart") then -- Get all the meshparts (not grassareas or grassclumps) in the grassfolder --
				grass:SetAttribute("OriginalCF", grass.CFrame) -- store their original cframe
				grass:SetAttribute("Bent", false) -- Set them as currently not being bent
			end
		
		
	end
end
  1. WaitForDescendants() this module script which i havent tested myself but seems pretty convenient
1 Like

The code you posted did not work.