How would I go about making Interactive plants/grass

Hey! I have been working on a game and I want to add a feature that I am struggling to figure out. I would like to make an interactive plant/grass system like The Wild West game on Roblox. Basically when the player touches the plant/grass it will tween in the direction the player is looking.

I have no idea how to go about this system and I really need help. I am not that good at scripting and i know very little about look vectors and CFrames.

I have tried to look through other topics about this, but I have no idea where to start?

4 Likes

Try experimenting with Touched and TouchEnded. Not 100% recommended but it might work.

1 Like

If I understood you right, you want to make a Plant that whenever you approach him / presses ‘E’ or something, it’d open a dialogue with him?

no not at all, I want it to move the plant when you walk into it like The Wild West

Oh, my bad. Never played The Wild West,

I believe you can move the plant model to a desired position when either a player’s distance from it is really close[meaning he’s walking into it], and if he actually reached distance 0, you could make the plant move aside or something.

A few articals on moving models:

1 Like

thanks, I will give that a try, only one thing I want to make it so that the plant moves in the direction the player is moving

here is an example, the plant tweens in the direction the player is walking
image
image

I think you can use CFrame.lookAt and look at the character’s torso.

1 Like

thanks! that’s a good idea, can you show me a code for that because I have tried that but I don’t think I did the code right. I tried basing it off this other persons topic but i could not get it to work

1 Like

here is Tyridge77’s post about it so you can get a better understanding

1 Like

CFrame.lookAt(plant.Position, torso.Position)

1 Like

thanks! i think this will work

Take a look onto CFrame and lookAt, they can help you alot :

https://developer.roblox.com/en-us/api-reference/datatype/CFrame

1 Like

thanks! I will do that right now

this is what I scripted but it does not work, Do you know why?

local grass = script.Parent.Parent.Grass
local ts = game:GetService(“TweenService”)

grass.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then

	local hum = hit.Parent:FindFirstChild("Humanoid")
	local movedir = hum.MoveDirection.Unit
	print(movedir.X, movedir.Z)
	local facevector = grass.CFrame * CFrame.Angles(math.rad(movedir.X), math.rad(0), math.rad(movedir.Z))

	local tween = ts:Create(grass, TweenInfo(.5), {CFrame = grass.CFrame * CFrame.Angles(math.rad(movedir.X), math.rad(0), math.rad(movedir.Y))})

	tween:Play()

end

end)

it says I ERROR: attempted to call a table value

What line of the script? You need to give all the info about the error possible.

ooh sorry ya line it is 15 i cant figure out why

so I was thinking and I decided to put all the plants in a folder, so I rewrote the script to make it work for all plants. The issue is that that doesn’t even work I set it to move the primary part but it won’t work. Btw I fixed the line 15 issue I had to put 0.5 in the TweenInfo spot

here is the new script

local grassfolder = workspace.Grass
local ts = game:GetService(“TweenService”)

while wait(.1) do
for i, grass in pairs(grassfolder:GetChildren()) do

	grass.HitBox.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			
			local hum = hit.Parent:FindFirstChild("Humanoid")
			local movedir = hum.MoveDirection.Unit
			print(movedir.X, movedir.Z)
			local facevector = grass.PrimaryPart.CFrame * CFrame.Angles(math.rad(movedir.X), math.rad(0), math.rad(movedir.Z))

			local tween = ts:Create(grass.PrimaryPart, TweenInfo(.5), {CFrame = grass.PrimaryPart.CFrame * CFrame.Angles(math.rad(movedir.X), math.rad(0), math.rad(movedir.Y))})
			
			tween:Play()
			
		end
	end)
end

end