(_|_) simple problem…

Quick explanation.

  1. Setup up bullet app state and attach
  2. Use the code provided in test walking character
  3. Make a minor mod to the player node

This has worked before… buuuut… this time, the player drops to the ground and just sticks there. Because of other stuff I am using in the scene, I can see that they character is being moved in the physics space and then bounced back to the original location. Let me post the relevant code and maybe someone can tell me where I hosed this.

[java]
BulletAppState bulletAppState;
CharacterControl character;
Node cameraNode;
ChaseCamera chaseCam;
boolean left = false, right = false, up = false, down = false;
Vector3f walkDirection = Vector3f.ZERO;
float walkSpeed = 1.0f;
boolean enableCharacter = false;

@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
stateManager.attach(bulletAppState);

	cam.setFrustumFar(36000f);
	float aspect = (float)cam.getWidth() / (float)cam.getHeight();
	cam.setFrustumPerspective( 45f, aspect, 0.1f, cam.getFrustumFar() );
	cam.update();
	cam.setLocation(cam.getLocation().add(200f, 0f, 200f));
	cam.lookAt(Vector3f.UNIT_Z, Vector3f.UNIT_Y);
	cam.setLocation(cam.getLocation().add(0f, 15f, 0f));
	flyCam.setMoveSpeed(100);
	
	pm = new PagingManager(exec, cam);
	pm.addPhysicsSupport(bulletAppState.getPhysicsSpace());
	
	int tSize = 12;
	int gSize = 41;
	float gQSize = 8f;
	
	TerrainGridDelegator terrainDelegator = new TerrainGridDelegator(assetManager, gSize, gQSize);
	terrainDelegator.setTile(((float)(gSize-1))*gQSize, tSize, true);
	terrainDelegator.setManagePhysics(true);
	terrainDelegator.setManageLOD(true);
	terrainDelegator.addLOD(PagingManager.LOD.LOD_1, 0f);
	terrainDelegator.addLOD(PagingManager.LOD.LOD_2, 180f);
	terrainDelegator.addLOD(PagingManager.LOD.LOD_3, 300f);
	
	terrainDelegator.addListener(this);
	
	pm.registerDelegator("Terrain", terrainDelegator, rootNode, 60);
	
	createCharacter();
	setupKeys();
	
	AmbientLight al = new AmbientLight();
	al.setColor(new ColorRGBA(1f, 1f, 1f, 1f));
	rootNode.addLight(al);
	
	ColorRGBA dayLight = new ColorRGBA(1f,1f,1f,1f);
	ColorRGBA nightLight = new ColorRGBA(.4f,.4f,.4f,1f);
	
	DirectionalLight sun = new DirectionalLight();
	sun.setDirection(new Vector3f(-.2f,-1f,-.2f).normalizeLocal());
	sun.setColor(dayLight);
	rootNode.addLight(sun);
}

private void createCharacter() {
	CapsuleCollisionShape capsule = new CapsuleCollisionShape(3f, 4f);
	character = new CharacterControl(capsule, 3.01f);
	
	cameraNode = new Node("Camera Node");
	cameraNode.addControl(character);
	character.setPhysicsLocation(new Vector3f(-140, 13, -10));
	rootNode.attachChild(cameraNode);
	
	chaseCam = new ChaseCamera(cam, cameraNode, inputManager);
	chaseCam.setDefaultDistance(.005f);
	chaseCam.setMaxDistance(40f);
	chaseCam.setDefaultHorizontalRotation(0f);
	chaseCam.setDefaultVerticalRotation(0f);
	chaseCam.setZoomSensitivity(1f);
	cam.setFrustumFar(36000f);
	float aspect = (float)cam.getWidth() / (float)cam.getHeight();
	cam.setFrustumPerspective( 45f, aspect, 0.1f, cam.getFrustumFar() );
	chaseCam.setUpVector(Vector3f.UNIT_Y);
	chaseCam.setMinDistance(.005f);
	chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
	chaseCam.setInvertVerticalAxis(true);
}

private PhysicsSpace getPhysicsSpace() {
	return bulletAppState.getPhysicsSpace();
}

private void setupKeys() {
	inputManager.addMapping("CharLeft", new KeyTrigger(KeyInput.KEY_A));
	inputManager.addMapping("CharRight", new KeyTrigger(KeyInput.KEY_D));
	inputManager.addMapping("CharUp", new KeyTrigger(KeyInput.KEY_W));
	inputManager.addMapping("CharDown", new KeyTrigger(KeyInput.KEY_S));
	inputManager.addListener(this, "CharLeft");
	inputManager.addListener(this, "CharRight");
	inputManager.addListener(this, "CharUp");
	inputManager.addListener(this, "CharDown");
}

@Override
public void simpleUpdate(float tpf) {
    if (enableCharacter) {
		Vector3f camDir = cam.getDirection().clone().multLocal(walkSpeed);
		Vector3f camLeft = cam.getLeft().clone().multLocal(walkSpeed);
		camDir.y = 0;
		camLeft.y = 0;
		walkDirection.set(0, 0, 0);

		if (left)	{ walkDirection.addLocal(camLeft); }
		if (right)	{ walkDirection.addLocal(camLeft.negate()); }
		if (up)		{ walkDirection.addLocal(camDir); }
		if (down)	{ walkDirection.addLocal(camDir.negate()); }
		character.setViewDirection(cam.getDirection().setX(0).setZ(0));
		character.setWalkDirection(walkDirection); 
	}
}

public void onAction(String binding, boolean value, float tpf) {
	if (binding.equals("CharLeft")) {
		if (value)	{ left = true; } else { left = false; }
	} else if (binding.equals("CharRight")) {
		if (value)	{ right = true; } else { right = false; }
	} else if (binding.equals("CharUp")) {
		if (value)	{ up = true; } else { up = false; }
	} else if (binding.equals("CharDown")) {
		if (value)	{ down = true; } else { down = false; }
	}
}

@Override
public void stop() {
exec.shutdown();
while (!exec.isTerminating()) { }
super.stop();
}

public void onAddToScene(Node node) {
	if (!enableCharacter) {
		List list = getPhysicsSpace().rayTest(cameraNode.getLocalTranslation(),cameraNode.getLocalTranslation().subtract(0f,200f,0f));
		PhysicsCollisionObject result = null;
		if (list.size() > 0) {
			result = list.get(0).getCollisionObject();
		}
		if (result != null) {
			getPhysicsSpace().add(character);
			enableCharacter = true;
		}
	}
}

public void onRemoveFromScene(Node node) {  }

[/java]

I know the following for sure:
RigidBodyControls are being created and added to scene properly for terrain tiles
Character control is being enabled when the terrain tile beneath the character control is added to scene.
(I know these are happening because the character drops and stops at the ground once the tile is loaded)
Physics engine is definately trying to move the character
(I can see new tiles being added/removed as the character attempts to move)

But… for some reason, it keeps getting thrown right back to the original start coords.

Thanks in advance.

EDIT: Guess I should also mention that I can see the physics objects via bulletAppState.getPhysicsSpace().enableDebug(assetManager); as well

Thanks, that emote worked, now I am stuck with your problem here :stuck_out_tongue:

FlyCam still enabled? As you basically tie everything together via the camera (CameraNode with PhysicsControl) a FlyCam or other cam control would wreak havoc. Like whats happening now is this: The physics control has some location it gets from the physics object and applies it to “its” spatial. The CameraNode in turn uses a CameraControl interface to access the camera and move it. Then you also use the cam direction etc. for your workings in simpleUpdate… So. A bit closely entangled atm, could be a lot, also outside the code you posted :slight_smile:

@normen That was a bad choice of names on my part… the cameraNode is actually a Node… not a CameraNode >.<

Hmmm… Whoa, your step size is huge… Try 0.1 or so ^^ (second parameter of CharacterControl constructor).

@normen no effect =( Sorry for the slow response. I just wanted to make sure I didn’t completely hack something else from the example in the process. This is a really odd thing. I’m going to try and rewrite the test via cut and paste from the example again and see what I missed. Strangest part is, I have a test from the original version of the paging system using this and it works fine. The only thing the paging system does is add the RBCs for the tiles and puts them in the physics space. I can see that it is still doing that, but something I’ve done in the test file hates me =)

Idk, just remember the PhysicsControl is also “just a control” that sets the values it wants to the spatial at some point… And then expects its work to be done.

@normen Just so you can laugh at me… this whole issue was due to me implementing InputListener instead of ActionListener. That’s what I get for typing >.< Soooooo sorry for being a bother!

:smiley: Just starting to write a test case sometimes helps :wink:

@normen Even better… I posted all “relevant” code… oh… except the relevant part >.<

This, my friend, is why we sound like broken records when we ask for test cases :wink:

Yeah, it is funny how often “excerpts” pass along the exact assumption that was making it tough for the OP to find the bug themselves… making it impossible to solve externally. Like when someone chops the stack trace right at the line where the problem actually is because the problem is “not in that code”.