Positioning problem/bug

Trying to create boxes upon keyboard input which are drawn beside the camera/player node and then are attached to rootnode at terrain.y (player.x/z) when enter is hit.



but… when i spawn a box it isn’t where i want/think it should be, it spawns way off in the distance at random(as in never at the same place)



log:

14-Jun-2011 17:11:39 com.jme3.scene.Node attachChild

INFO: Child (TestBox) attached to this node (Player)

(-46.522358, 4.499937, 165.05972) – println of cam.getLocation

14-Jun-2011 17:11:39 com.jme3.scene.Node detachChildAt

INFO: Child removed.

14-Jun-2011 17:11:39 com.jme3.scene.Node attachChild

INFO: Child (TestBox) attached to this node (Player)

Camera Position: (-46.522358, 4.499937, 165.05972)

Camera Rotation: (0.08534075, -0.10632563, 0.009160397, 0.99061996)

Camera Direction: (-0.20909306, -0.17102848, 0.9628236)

code:

[java] private Geometry getTempBox(){

Geometry temp = new Geometry(“TestBox”, new Box(2, 1, 2));

System.out.println(cam.getLocation().toString());

temp.setLocalTranslation(cam.getLocation());

Material mat = new Material(this.assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

mat.setColor(“Color”, ColorRGBA.randomColor());

temp.setMaterial(mat);

return temp;

}[/java]

image of the problem (didnt embedd it as its 1280x720) IMAGE

and similar problem when i place (hit enter) to attach to terrain it moves it somewhere else.

just in case :

[java] } else if (binding.equals(“Spawn”)) {

playersnode.detachAllChildren();

playersnode.attachChild(getTempBox());

} else if (binding.equals(“Place”)){

if(playersnode.getChild(“TestBox”) != null){

Spatial temp = playersnode.getChild(“TestBox”);

temp.setLocalTranslation(player.getPhysicsLocation().x, sceneModel.getLocalTranslation().y, player.getPhysicsLocation().z);

attachToPhysics(temp);

rootNode.attachChild(temp);

playersnode.detachChildNamed(“TestBox”);

}

}[/java]

and :

[java] private void attachToPhysics(Spatial s){

s.addControl(new RigidBodyControl(CollisionShapeFactory.createMeshShape(s), 0));

bulletAppState.getPhysicsSpace().add(s.getControl(0));

}[/java]

i tried with using the physics location of the CharacterControl used to move around (which the camera follows) but same issue.

Its because the RigidBodyControl defines the location of the spatial as soon as its attached. You can either set the location and then add the rigidbody (it will take its location from the spatial) or you can set the rigidbodys location or you can set the rigidbody to kinematic mode so it will not fall but sync its location with the spatials.

Ooo thanks, that solves the Placing, however the problem of "Spawn"ing which shows the box at random location is the main problem. Maybe i didn’t explain enough.

idea: player presses V spawns a geometry box in front of them (Attached to player’s node so it follows the player as he moves till he presses enter), the geometry box spawns but at random location even though i setLocation to cam.getLocation. this is prior to attaching physics

incase anyones wandering or similar problem, fixed the spawning movement issue by forcing position of temp box in the update loop.