hi, i searched the jme api and there is no method to move the spatial to go to the desired world position.
so far i used this method, i dont know if it works in all cases !!!
[java]public static void setPosition(Spatial node, Vector3f position)
{
node.center();
Vector3f scale = node.getWorldScale();
node.move(scale.mult(0.5f));
node.move(position);
}
public static Vector3f getPosition(Spatial node)
{
return node.localToWorld(Vector3f.ZERO, null);
}[/java]
Is there a better way ?
jme flawed user: cannot read API and doesn’t find getWorldTranslation
Edit: and setting a world translation cannot work, its a combination of lots of parent positions, how should the API decide which of those to move to get the new location? So ofc you go spatial.setLocalTranslation(spatial.worldToLocal(worldLocation)) :roll:
Ops sorry about that i searched and i didnt see the method getWorldTranslation.
spatial.setLocalTranslation(spatial.worldToLocal(worldLocation)) doesnt work.
But player.setLocalTranslation() works.
Thank you,
I think that rotation will mess up alot in that eqvation. You could probebly get out a formula/method for getting the localposition given a world position, but that would include rotation and position of all parents to your object.
detailed explanation :
[java]System.out.println("Before pos : "+player.getWorldTranslation());
player.setLocalTranslation(player.worldToLocal(new Vector3f(0f,0f,10f),null));
System.out.println("After pos : "+player.getWorldTranslation());
[/java]
Output :
Before pos : (0.0, 0.0, 66.0)
After pos : (0.0, 0.0, -56.0)
[java]System.out.println("Before pos : "+player.getWorldTranslation());
player.setLocalTranslation(new Vector3f(0f,0f,10f));
System.out.println("After pos : "+player.getWorldTranslation());
[/java]
Output :
Before pos : (0.0, 0.0, 66.0)
After pos : (0.0, 0.0, 10.0f)
question : will this method continue to work after rotations / scaling or will it stop working then ?
testing complete, player.setLocalTranslation(position); works in all cases.