0

First up I am a newbie on Maxscript. I have seen script for collision detection for specific objects I also want to write to a txt file the objects that are For example all objects with the name "Prism*" that collide with Cylinder001 I want to colour red and write to the text file. I have made some attempt at code;

     fn collisionDetection node1 node2 =
     (
      if intersects node1 node2 then 
     (node1.mesh * node2.mesh).numverts > 0
     else
     false
     )

    dir =getFilenamePath (getThisScriptFilename())
    makeDir  dir
   OutputTextFile = dir + "Output.txt"
   if (doesFileExist OutputTextFile) do deleteFile OutputTextFile 
  filestreamvar = openFile OutputTextFile mode:"w"
     if  filestreamvar == undefined do 
    (
createFile OutputTextFile
filestreamvar = openFile OutputTextFile mode:"w"

        myObjects = $'Prim*' as array

        for i = 1 to myObjects.count do
        (
            nam = myObjects[i].name
      if collisionDetection $myobject[i] $'Cylinder001' do 
   (    
print myobjects[i] to:filestreamvar
            )
    )   
    edit OutputTextFile
   close filestreamvar

I haven't added code for colouring the object that is true as I am struggling with the output in a textfile already. Can somebody please help? thank you.

  • Sorry I did as you suggested if collisionDetection myObjects[1] $'Cylinder001' do however it seems to output a number of the myobjects into the text file regardless of whether they collided with the cylinder or not. Is there a better way of writing this so it only picks up the myobjects that actually collide with the cylinder? – Mark Roberts Aug 20 '14 at 22:23

1 Answers1

1

Your error is in the line if collisionDetection $myobject[i] $'Cylinder001' do

Your referencing $myobject as if it were a named item in the scene, but its actually a local variable. That means that you pass undefined to collisionDetection

pass myObject[1] instead, that should get it working

FrozenKiwi
  • 1,362
  • 13
  • 26