[SOLVED] SetLocalTranslation

Hello. im making a game, and i’ve got a player with BetterCharacterControl and terrain with RigidBodyControl with mass 0. The collision detection works perfectly, but i cannot move the terrain. setLocalTranslation() has no impact on the terrain (it worked before i added physics to it). I managed to move the player with .warp(), but have no clue how to move the terrain.
Here are the methods

private void initTerrain(){
    terrainRigidBody = new RigidBodyControl(0); // static terrain physics
    AbstractHeightMap heightmap = null;
    Texture heightMapImage = assetManager.loadTexture(
            "Textures/CustomHeightMaps/heightMapa.png");
    heightmap = new ImageBasedHeightMap(heightMapImage.getImage());
    heightmap.load();
    int patchSize = 65;
    terrainTile = new TerrainQuad("my terrain", patchSize, 257, heightmap.getHeightMap());
    terrainTile.addControl(terrainRigidBody);
    rootNode.attachChild(terrainTile);  
    Material terrainMatTest = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    terrainMatTest.setTexture("ColorMap", assetManager.loadTexture("Textures/trawa.jpg"));
    terrainTile.setMaterial(terrainMatTest);
    terrainTile.setLocalTranslation(-25,-100,25);
    getPhysicsSpace().add(terrainTile);
    
    
    }
private void initPlayer(){
        playerGhostControl = new GhostControl(new BoxCollisionShape(new Vector3f(1,1,1))); // ghost control player
        playerCharacterControl = new BetterCharacterControl(1f,1.9f,1f);
        
        player = assetManager.loadModel("Models/Ochrona1/Ochrona1.j3o");
        playerNode = new Node("player Node");
        playerNode.addControl(playerGhostControl);
        playerNode.addControl(playerCharacterControl);
        playerCharacterControl.setJumpForce(new Vector3f(0,5f,0));
        playerCharacterControl.warp(new Vector3f(0,10,0));
        getPhysicsSpace().add(playerCharacterControl);
        getPhysicsSpace().addAll(playerNode);
        playerCharacterControl.setGravity(new Vector3f(0,-1f,0));

        playerNode.setLocalTranslation(-5,0,5);
        
        rootNode.attachChild(playerNode);                                        
        playerNode.attachChild(player);
        getPhysicsSpace().add(playerGhostControl);

moreover, the player wont rotate on my input, just as if my code was not even there. I am new to gamedev and i believe its a newbie question, but cant think of any reasonable explanation
the listener code:

if(name.equals("Forward")){
         cameraRotation = chaseCam.getHorizontalRotation();  // horizontal rotation in radians
         quaternionCamRotation.fromAngles(0, -cameraRotation-FastMath.HALF_PI, 0); // 
           
  
           currentPlayerRotation = playerNode.getWorldRotation();
   
             
           Quaternion q3 = currentPlayerRotation.slerp(currentPlayerRotation, quaternionCamRotation, tpf*8);
           // q3 is a helper quat for code readability
           playerNode.setLocalRotation(q3);
           

           lastAnalogInput=name;

           
       }
       else if(name.equals("Backward")){
         cameraRotation = chaseCam.getHorizontalRotation();  // horizontal rotation in radians
         quaternionCamRotation.fromAngles(0, -cameraRotation+FastMath.HALF_PI, 0); // 
           
  
           currentPlayerRotation = playerNode.getWorldRotation();
   
             
           Quaternion q3 = currentPlayerRotation.slerp(currentPlayerRotation, quaternionCamRotation, tpf*8);
           // q3 is a helper quat for code readability
           playerNode.setLocalRotation(q3);


           lastAnalogInput=name;


            }

Once you add physics to things they are controlled by the physics and you have to move the physics.

…else the rigid body is constantly moving it back where it was.

1 Like

okay,thank you! Will give it a go in a second

okay,so it works. Is there an equivalent of setLocalRotation() for BetterCharacterControl? I tried setViewDirection() but it works instantly, and it takes Vector3f as a parameter, and i want the player to rotate slowly, which i did previously by using quaternion.slerp. Is there a method that is similar to setLocalRotation() that takes quaternion as a parameter?

something that would be equivalent to this but regarding BetterCharacterControl

BetterCharacterControl doesn’t provide a mechanism to re-orient its physics object. That’s because the object is capsule-shaped and always upright. The direction the character is facing has no effect on the physics.

To rotate the character in the horizontal plane, use setViewDirection().

Did you get rotation working to your satisfaction?

yes i did, thanks a bunch for help!
solved like this:

if(name.equals("Forward")){

           
         cameraRotation = chaseCam.getHorizontalRotation();  // horizontal rotation in radians
           quaternionCamRotation.fromAngles(0, -cameraRotation-FastMath.HALF_PI, 0); // 
           
  
           currentPlayerRotation = playerNode.getWorldRotation();
    
           Quaternion q3 = currentPlayerRotation.slerp(currentPlayerRotation, quaternionCamRotation, tpf*4);
           
           playerViewDirection.set(q3.getRotationColumn(2));
           
       }
1 Like