[Closed] This should be easy?
I am writting a script that loops through the random placement of different size boxes on a plane. I am trying to detect within the loop when two boxes intersect and if they do then move the newly created box on top of the existing.
The problem that I am having is in defining the nodes for the “intersects <node> <node>” method since I only know one of them.
thanks for the help
-joe
as a small example:
Unit_Count1 = 2 ---determined by the Main script
UnitNumber = 30 ---determined by the Main script
Actualunits = Unit_Count1 ---determined by the Main script
for i = 1 to UnitNumber while UnitNumber >= ActualUnits do
(
Units = random 1 7 ---determined by the Main script
LotUnit_Count = Units
Actualunits = Actualunits + LotUnit_Count
if Actualunits >= UnitNumber then exit ---Bail out density is over the limit
else
(
Lot = Box prefix: "Lot"
Lot.pos.x = random -125 150
Lot.pos.y = random -80 40
Lot.height = Units * 10
if (intersects Lot $Lot*) == true then
(
print "INTERSECTION"
---then move "Lot" to surface of intersecting box
)--end if
)--end if
)--end loop
Hi!
Try this:
tempLot = Box pos:[random -125 150, random -80 40, 0] height:(Units * 10)
if (for i in $Lot* where intersects tempLot i collect i).count > 0 then
(
print "INTERSECTION"
---then move "tempLot" to surface of intersecting box
)--end if
tempLot.name = "Lot"+tempLot.name
you could also enhance this by sticking the for loop outside the if and assigning it to a variable, then you will know if it’s intersecting with more than one box and process accordingly.
Thanks,
Ok, that works to find out if boxes intersect one another, now I am stuck on getting the z position in the correct location. I have tried two versions with the same end result… the box getting moved in the z direction is moving too far, it is taking the height of the box that it intersects with (all of them, and adding up their heights) plus its own height.
intention:
to loop through the random placement of boxes with varying height. if a new box is created that intersects with a present box move the new box in the z axis to the highest face where it is no longer intersecting any boxes (ie. if the move to the top of the intersecting box causes it to intersect with another box then move to the top of it)
I think I am missing something fundamental here
thanks
for t = 1 to 8 do
(
tempLot = Box pos:[random -80 50, random -80 40, 0] height:(random 10 30) prefix: "Lot"
if (for i in $Lot* where (intersects tempLot i) collect i).count > 1 then ---if there is an inersection then...
(
for t in $Lot* where (intersects tempLot t) do
(
tempLot.pos.z = (t.max.z)
)
)
)
and a more complex version of the same thing based on an example in the help file
fn find_intersection target_Lot_z Lot_Moving =
(
local testRay = ray Lot_Moving.pos [0,0,-1]
local TargetMaxZ = target_Lot_z.max.z
testRay.pos.z = TargetMaxZ + 0.0001 * abs TargetMaxZ
intersectRay target_Lot_z testRay
)
for t = 1 to 8 do
(
tempLot = Box pos:[random -80 50, random -80 40, 0] height:(random 10 30) prefix: "Lot"
if (for i in $Lot* where intersects tempLot i collect i).count > 1 then
(
print "intersection"
for t in $Lot* where intersects tempLot t do
(
int_point = find_intersection t tempLot
if int_point != undefined then tempLot.pos = int_point.pos
)
)--end if
)--end for loop
try this:
for t = 1 to 8 do
(
tempLot = Box pos:[random -80 50, random -80 40, 0] height:(random 10 30) prefix:"Lot"
for i in $Lot* where i != tempLot and (intersects tempLot i) do tempLot.pos.z = i.max.z
)