I’m making grass which spawns in a grid and chooses a random rotation, and point around it’s grid position. How would i make it face torwards the camera, but also slightly face torwards it’s original position. I want to do this to make the grass look more ‘full’.
Video of what i have so far:
Code:
--||SERVICES||--
local RepStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")
--||FOLDERS||--
local Assets = RepStorage.Assets
--||VARIABLES||--
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humrp = Character.HumanoidRootPart
local GrassBlade = RepStorage.Assets.Grass.GrassBlade
--||SETINGS||--
local xdistanceBetweenBlades = 2
local zdistanceBetweenBlades = 2
local offset = Vector3.new(xdistanceBetweenBlades, 0, zdistanceBetweenBlades)
local Tag = "Grass"
local Blades = {}
function setGrassCFrame(newBlade, randSizeY, randSizeX , topLeftPos, newOffset)
newBlade.Size = Vector3.new(randSizeX, randSizeY, newBlade.Size.Z)
newBlade.CFrame = CFrame.new(topLeftPos + newOffset) * CFrame.Angles(0, math.rad(math.random(-360, 360)), 0)
end
function CreateGrass(xGridSize, zGridSize, topLeftPos, GrassFolder)
for z = 0, zGridSize do
for x = 0, xGridSize do
local newBlade = GrassBlade:Clone()
newBlade.Parent = GrassFolder
local random = Random.new()
local newOffset = Vector3.new((xdistanceBetweenBlades * x) + random:NextNumber(-1, 1), newBlade.Size.Y / 2, (zdistanceBetweenBlades * z) + random:NextNumber(-1, 1))
local randSizeY = math.random(3, 4)
local randSizeX = randSizeY/6
setGrassCFrame(newBlade, randSizeY, randSizeX , topLeftPos, newOffset)
Blades[newBlade] = {CFrame = newBlade.CFrame}
end
end
end
for i, v in pairs(CollectionService:GetTagged(Tag)) do
local targetPart = v
local GrassFolder = targetPart:FindFirstChild("Blades")
if not GrassFolder then
GrassFolder = Instance.new("Folder", targetPart)
GrassFolder.Name = "Blades"
end
local targetPartSizeX = targetPart.Size.X
local targetPartSizeZ = targetPart.Size.Z
local targetPartPosX = targetPart.Position.X
local targetPartPosZ = targetPart.Position.Z
local topLeftPos = Vector3.new((targetPartPosX - (targetPartSizeX / 2)) + xdistanceBetweenBlades , targetPart.Position.Y + (targetPart.Size.Y / 2) , (targetPartPosZ - (targetPartSizeZ / 2)) + zdistanceBetweenBlades)
local xGridSize = math.floor((targetPartSizeX - (xdistanceBetweenBlades + 1)) / xdistanceBetweenBlades)
local zGridSize = math.floor((targetPartSizeZ - (zdistanceBetweenBlades + 1)) / zdistanceBetweenBlades)
task.spawn(function()
task.wait(5)
while true do
local mag = (targetPart.Position - Humrp.Position).Magnitude
local children = targetPart.Blades:GetChildren()
print(#children)
if mag > 1000 then
if targetPart:GetAttribute("GraphicalStage") ~= "Shadows" then
targetPart:SetAttribute("GraphicalStage", "Shadows")
for i, v in targetPart.Blades:GetChildren() do
v.CastShadow = false
print("removedShadows")
end
end
end
wait(1/4)
end
end)
CreateGrass(xGridSize, zGridSize, topLeftPos, GrassFolder)
end