[Fisica] How to get a body by its name rather than its position

edited November 2013 in Library Questions

Hi, I was wondering whether it would be possible to retrieve a body just knowing its name, ie adding a method

FBody World.getBody(String bodyName)

It doesn't seem to be possible yet but is there any update soon?

Thanks.

Cheers, Yohan.

Tagged:

Answers

  • Well, ok, sorry about this post, I guess I can just add it myself in my script:

    FBody getBody(String bodyName){
      ArrayList<FBody> bodies=world.getBodies();
      for(FBody b:bodies){
        try{
          if(b.getName().equals(bodyName)){
          return b;
          }
        }catch(NullPointerException e){
          println(e);
        }
      }
    
      return null; 
    }
    
Sign In or Register to comment.