I am new to JME and just started with making a game. I have gone through the tutorials. I have two models in the scene and I want to move one model by mouse and check for the collision with the other model and if collision takes place I want to move the other object. I do not know how to do it. Can any one please help me?
I have already gone through the above example. But there is no code to show how to move an object ( model ) by mouse. There is only click event listener by which you can initiate the shoot event. I have tried Analog listener , but no result. Is there any other way to get the mouse axis ( x, y ) when we move the mouse?
@leorius said:
I have already gone through the above example. But there is no code to show how to move an object ( model ) by mouse. There is only click event listener by which you can initiate the shoot event. I have tried Analog listener , but no result. Is there any other way to get the mouse axis ( x, y ) when we move the mouse?
You say you have tried analog listener with no result. What does that mean? Was your listener never called? That’s a setup problem… because I can assure you that analog listeners are called when the mouse moves.
Here is what I have trtied.
in simpleInitApp():
this is the code:
inputManager.addMapping(“MoveX”, new MouseAxisTrigger(MouseInput.AXIS_X, false));
inputManager.addListener(analogListener, “MoveX”);
After the simpleInitApp this is the code before simpleUpdate():
private AnalogListener analogListener = new AnalogListener()
{
public void onAnalog(String name, float value, float tpf)
{
mousex = MouseInput.AXIS_X;
mousey = MouseInput.AXIS_Y;
java.lang.RuntimeException: Uncompilable source code – Erroneous tree type:
Is generally a sign that the netbeans incremental compiler is messing up. I got so tired of these sorts of errors that I eventually turned it off. You can do this in your project settings by going to the compile tab and turning off “Compile on save”. Then rebuild your project and see if that gets you past it.
MouseInput.AXIS_X isnt the x position of the mouse, it’s just some random integer assigned to that variable. Its just used as a common definition for that mouse axis, which in this case is used by MouseAxisTrigger.
To get the screen coordinates of the mouse use inputManager.getCursorPosition(). Then [if you need it for your game] use ray casting with your cursor position to find what geometry in the world your mouse is over and where its at in the 3d world etc. (which I think is in a previous link posted by @mifth)