Best way to align one object on top of another?

Hey everyone, so I have generated 20 cubes of random scale on the vertex points of a plane.

Say i generate 20 cyclinders, what would be the best way to align each cylinder to each cube's top face?

I was considering the Ray thingy but im not sure if thats appropriate.

thanks :)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Vapourise's picture

P.S [RandomBox.center.x,Rando

P.S

[RandomBox.center.x,RandomBox.center.y,RandomBox.max.z]

Does the .max refer to the max distance from the pivot point of the object i.e. the top? If so how would you then define the .max distance in the negative z?

K

Anubis's picture

BoundingBox

.max/.min give you boundingbox dimension and have nothing related to the pivot. Maybe you ask for obj.min.z ?

my recent MAXScripts RSS (archive here)

Vapourise's picture

Hey guys thnks for the

Hey guys thnks for the replies, Mjbeg I will try that code out when I get back on my PC :) Joker, I am currently trying to put together a script to create some Favela like geometry, I have managed to create the random base blocks over a plane using the vert position but now I am unsure how to add to those base blocks.

Basically, I was thinking of using a loop to go through all the pieces that have been generated and align another piece of geometry to a face on those cubes.

How to define which face and how to align it with it I am unsure of? I thought it may have something to do with all That Matrix jazz. I managed to have a loop create the initial geometry and make a duplicate of it but couldn't get it to scale and align it the way i wanted.

I know that systems like this already exist and there are many city/building generators etc but I am trying to learn for myself and not just copy everyone else's work.

If you need to know more about what I want to achieve then I can explain but didnt wanna bore you guys :P Thanks again!

JokerMartini's picture

When you randomly generate

When you randomly generate the cubes have them align to each others top face on creation.
It depends exactly what you are going for with this script and what is the purpose.
I could put something together probably but you'd need to elaborate a bit more on what exactly you are trying to do?

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

mjbg's picture

well.. i dit it on a plane

well.. i did it on a plane converted to editable poly.. i dont know how to use the verts of a plane.

for o in 1 to $.verts.count do -- Plane (converted to poly) selected
(
RandomSize = random 10 50
RandomBox = box pos:$.verts[o].pos length:RandomSize width:RandomSize height:RandomSize
RandomCyl = Cylinder pos:[RandomBox.center.x,RandomBox.center.y,RandomBox.max.z] height:RandomSize Radius:RandomSize
)

or this to each cylinder match the box size

for o in 1 to $.verts.count do
(
RandomSize = random 10 50
RandomBox = box pos:$.verts[o].pos length:RandomSize width:RandomSize height:RandomSize
RandomCyl = Cylinder pos:[RandomBox.center.x,RandomBox.center.y,RandomBox.max.z] height:RandomBox.height Radius:(RandomBox.height/2)
)
br0t's picture

I think you can check each

I think you can check each faces normal direction to see which face is the top one, but I dont know the code to do it, maybe someone else can help.

Never get low & slow & out of ideas

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.