The outcome is not the same. If you get the same vector or a new one, thats a completely different thing. If you got the Vector3f from something like getLocalTranslation() and then do normalizeLocal() you could actually change the Spatials location because that Vector3f is used by the scenegraph to locate the Spatial. On the other hand when you create a new Vector and then perform some operation on it theres no need to make a new Vector3f each time.
Use normalizeLocal like this in your code:
[java]
if (left) { walkDirection = cam.getLeft().mult(.235f);}
if (right) { walkDirection = cam.getLeft().negate().normalizeLocal().multLocal(.235f); }
if (up) { walkDirection = new Vector3f(cam.getDirection().getX(),0,cam.getDirection().getZ()).normalizeLocal().multLocal(.5f); }
if (down) { walkDirection = new Vector3f(-cam.getDirection().getX(),0,-cam.getDirection().getZ()).normalizeLocal().multLocal(.5f); }
playerPhysicsNode.setWalkDirection(walkDirection);
[/java]
Also you should probably remove the new Vector and replace it with a global variable to not produce too much garbage for the garbage collector.
1 Like