Inoob8C

Grass Culling Physics Disable

Jul 31st, 2024
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. --!native
  2. --!strict
  3. local CollectionService = game:GetService("CollectionService")
  4. local GrassPhysics = require(script.Parent.Parent.Physics.GrassPhysics)
  5. local Camera = workspace.CurrentCamera
  6.  
  7. local function updateVisibility(): ()
  8. local viewDirection = Camera.CFrame.LookVector.Unit
  9. local function processObject(obj: BasePart): ()
  10. local partPosition = obj.Position
  11. local toObject = (partPosition - Camera.CFrame.Position).Unit
  12. local dotProduct = viewDirection:Dot(toObject)
  13.  
  14. if dotProduct > 0 then
  15. print("Object in view: " .. obj.Name) -- Debugging
  16. GrassPhysics:enableGrass(obj)
  17. else
  18. print("Object out of view: " .. obj.Name) -- Debugging
  19. GrassPhysics:disableGrass(obj)
  20. end
  21. end
  22.  
  23. for _, obj in CollectionService:GetTagged("Grass") do
  24. processObject(obj)
  25. end
  26. end
  27.  
  28. Camera:GetPropertyChangedSignal("CFrame"):Connect(function()
  29. updateVisibility()
  30. end)
  31.  
  32. print("p")
Advertisement
Add Comment
Please, Sign In to add comment