[SOLVED] Model twitches (blinking) when character control move

effect:

maybe low fps? or how to make smooth movement of the model behind the capsule?

model disappears and then appears elsewhere.

1 Like

solved bad video card :

1 Like

In my experience you have this issue with low fps when you update the camera position in update() instead of render(). I just wanted to point that out in case it happens again.

2 Likes

THANKS.

But what different between render and update?

1 Like

I need update camera in render method?

Ind what need do in update method?

example pleas… thanks

1 Like

render() is called before the rendering of the scene, update is called after.
If you are using an AbstractControl you have to override controlRender(RenderManager,ViewPort), if you are using an appstate you have to override render( RenderManager ), if you are updating the camera from a SimpleApplication instead, you have to override simpleRender(RenderManager) . That’s it, you move the camera update from your update/controlUpdate/simpleUpdate method to one of these.

The idea is: if the position is updated in the update() method, you are always one frame behind.

1 Like

Understand.

This:

camDir.set(cam.getDirection()).multLocal(0.3f);
camLeft.set(cam.getLeft()).multLocal(0.2f);

         Vector3f location = new Vector3f(players.get(localPlayerId).characterModel.getWorldTranslation().x,players.get(localPlayerId).characterModel.getWorldTranslation().y + 2f,players.get(localPlayerId).characterModel.getWorldTranslation().z);
         
         cam.setLocation(location);

insert in render?

1 Like

yes

1 Like

Need add to render other methods…

What happen in render?

If I override it

1 Like

That’s a java question, read the official documentation if you are not familiar with overriding a method.

2 Likes

Work very good.

public void simpleRender(RenderManager rm) {
    if(players.get(localPlayerId) != null){
        camDir.set(cam.getDirection()).multLocal(0.3f);
        camLeft.set(cam.getLeft()).multLocal(0.2f);

        
        
        Vector3f location = new Vector3f(players.get(localPlayerId).characterControl.getPhysicsLocation().x,players.get(localPlayerId).characterControl.getPhysicsLocation().y + 2f,players.get(localPlayerId).characterControl.getPhysicsLocation().z);

        cam.setLocation(location);
    }
}
1 Like

update is also called before the rendering of the scene… but simpleUpdate() and appstate.update() are called before the controls have been updated. So if you sync the camera to a spatial on simpleUpdate() then you miss the changes that are about to happen in its control.

Edit: this was in response to @RiccardoBlb’s assertion that update happens after rendering. From a certain perspective, that’s true… but then render happens after render, too. In one update pass, update is called first… then the control updates… then render.

2 Likes

So I have to return this part of the code to update?

    Vector3f location = new Vector3f(players.get(localPlayerId).characterControl.getPhysicsLocation().x,players.get(localPlayerId).characterControl.getPhysicsLocation().y + 2f,players.get(localPlayerId).characterControl.getPhysicsLocation().z);

    cam.setLocation(location);
1 Like