Pick a brick,but I can not pick

when i write if (target.getName().equals(Red Cube")){target.rotate(0,-1,0); The panel said it cannot find getName and rotate cannot use equal. I donot know.

https://www.mikeash.com/getting_answers.html

2 Likes

It is hard to understand your question and you could have had a better topic name but, I typed in the code (corrected - you missed one " before Red Cube. (But, that may just be a typo in the message…) ) and it worked fine. You may have figured out the problem by now.

  Node target = ((Node)spatial);
  //Spatial target = spatial;
  if (target.getName().equals("Red Cube")){
  	target.rotate(0, -1, 0);
  }

Either spatial or node target works fine.

I do not know the code I write can not work. I can not find the result. Thanks.

This is the code I try. Thanks

You forgot this part. After pasting in the code, you can select it and hit the big " at the top left of the text box.

  if (action.equals(MAPPING_ROTATE)){
      //System.out.println("onAnalog-mapping_rotate");
      CollisionResults results = new CollisionResults();
      Vector2f click2d = inputManager.getCursorPosition();
      Vector3f click3d = cam.getWorldCoordinates(new Vector2f(click2d.getX(), click2d.getY()), 0f);
      Vector3f dir = cam.getWorldCoordinates(new Vector2f(click2d.getX(), click2d.getY()), 1f).subtractLocal(click3d);
      Ray ray = new Ray(click3d, dir);
      rootNode.collideWith(ray, results);
      if (results.size() > 0){
          Geometry target = results.getClosestCollision().getGeometry();
          System.out.println("target's parent=" + target.getParent().getName());
  }
      else{
  //nothing selected
  }

Otherwise, you are not defining ‘taget’.
I hope this helps

Thank you

You’re welcome. Is it working now?
Can you pick a brick, yet?
Do you have the jmonkeyEngine 3.0 book. That’s where I got the code from.

Screenshots? wow! If sombody want to scare me he only need to post screenshots of logs or code :wink:

Why not copy the code, put three backticks hit enter, paste code hit enter, put another three backticks enter and post this? Just for the next time?

Actuually I think there is something wrong in my code ,or I still need more time to learn JME3, so I decide to rewrite it . I have one book about JME3,