Discord
Login
Community
DARK THEME

How to get length or width of a Matter.Body.rectangle()

the microstudio documentation tells us that to get a shape's X or Y value, its [shape].position.x. Is there something similar to get the length or width of an object or another parameter?

When you create an object, you know its dimensions. Immediately after creating it, you can add width and height fields to it

This will show the approximate boundaries of the object - they will be false (larger) than the real ones when the object is rotated about the reference axis.

   bounds = Matter.Bounds.create(box.vertices)
   width = bounds.max.x - bounds.min.x
   height = bounds.max.y - bounds.min.y

Or you calculate the distance between vertices. box.vertices << you take two vertices and count the distance.

https://microstudio.io/PaulSt/mattertest2/

https://microstudio.io/i/PaulSt/mattertest2/

when you enter the name of the object in the console, you will receive a list of available methods and fields.

you can also check it from the inside

printField = function( obj, str )
  if obj.type == "object" then 
    for field in obj
      local fieldType = obj[ field ].type
      if ( fieldType != "function") and ( fieldType != "object") then
        print( "Field = " + str + field + " type = " + obj[field].type )
      end
    end
    for method in obj 
      if obj[ method ].type == "object" then
        printField( obj[ method ], str + "." + method  )
        printMethod( obj[ method ], str + "." + method  )
      end
    end
  end
end

printMethod = function( obj, str )
  if obj.type == "object" then 
    for method in obj
      if obj[ method ].type == "function" then 
        print( "Method = " + str + "." + method + " type = " + obj[method].type )
      end
    end
  end
end


// Prints all fields and methods 
// in the class along with inherited methods.
printObject = function( obj )
  printField( obj, ">>> " )
end

Ok, thanks. This is what i thought I would have to do, Thanks!

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community