I want to make sure that when these two cylinders grow in length, they won’t ever overlap.
This is all I have so far, but it doesn’t seem to work. Mind you I’m not very good at CFrame.
RedCylinder.CFrame = GreenCylinder.CFrame * CFrame.new(0, (GreenCylinder.Size.Y / 2 - (GreenCylinder.Size.Y * self.YSpawn)), 0)
-- Gets where the red cylinder should spawn, not accurate to the image above sorry.
RedCylinder.CFrame = CFrame.lookAt(RedCylinder.Position, GreenCylinder.Position - Vector3.new(math.random(-360, 360),math.random(-360, 360),math.random(-360, 360)))
-- Makes the RedCylinder look away from the GreenCylinder and adds random orientation, doesn't work 100% of the time however.
Just trying to make the RedCylinder be able to greow in the same general direction (in this case upwards) but also not ever intersect with the GreenCylinder. Or any other RedCylinders in the future that might be added?
Any help is appreciated. My current method is just to have the RedCylinder look away from the GreenCylinder and add random orientation, however it doesn’t always work.
Not sure how to ask this question, but how can I make the orientation/math you sent be relative to its current orientation?
Both green and red cylinders can generate on any surface normals. So the math you sent does work for cylinders that generate on the ceiling, however ones that generate on the walls or floor become inverted.
Imagining if the red line was a floor that the cylinders shouldn’t grow into, how can I always have the cylinders generate facing up from it?
I use :Raycast() to actually get the cylinder spawning positions, do I need to use RaycastResult.Normal for this?
are they still colliding with each other or just not growing in the right direction? I think it should work for any orientation. probably. that’s me talking, though.
to make sure they grow towards the normal I would try
local rng = Random.new()
local root = CFrame.lookAt(rc.position, rc.position + rc.Normal)
local cf = root:ToWorldSpace(CFrame.Angles(rng:NextNumber(-math.rad(45.0), math.rad(45.0)), rng:NextNumber(-math.rad(45.0), math.rad(45.0)), math.rad(90.0))
perhaps unorthodox, but I often use CFrame.lookAt + ToWorldSpace because I’m bad at math. you might need to mess with the CFrame.Angles order a bit, I kind of just guessed.
that is very strange, are you sure you’re not accidentally using the same rng state each time (i.e. Random:Clone(), Random.new(tick()) in the same frame)? that’s all I could think of.