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?
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.
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
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
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