对于这种问题 LibGDX 3D camera implementation(更多清晰描述问题的图片) 我得到了一个玩家运动和相机的实现, 我想在 Ashley ECS 中制作这样的相机
目前我们在玩家身上放置了一个摄像头,但我们想要达到的是一个在玩家移动时旋转的摄像头,一个放置在玩家身后并始终注视玩家的摄像头
//Move
if (-PlayerController.getMovementVector().y < 0 || Gdx.input.isKeyPressed(Input.Keys.W)) {
characterComponent.walkDirection.add(camera.direction);
}
if (-PlayerController.getMovementVector().y > 0 || Gdx.input.isKeyPressed(Input.Keys.S)) {
characterComponent.walkDirection.sub(camera.direction);
}
if (-PlayerController.getMovementVector().x > 0 || Gdx.input.isKeyPressed(Input.Keys.A)) {
tmp.set(camera.direction).crs(camera.up).scl(-1);
}
if (-PlayerController.getMovementVector().x < 0 || Gdx.input.isKeyPressed(Input.Keys.D)) {
tmp.set(camera.direction).crs(camera.up);
}
characterComponent.walkDirection.add(tmp);
if (Gdx.app.getType() == Application.ApplicationType.Android) {
characterComponent.walkDirection.scl(1f * delta); //Vitesse Déplacement Personnage
}
else if (Gdx.app.getType() == Application.ApplicationType.iOS) {
characterComponent.walkDirection.scl(1f * delta); //Vitesse Déplacement Personnage
}
if (Gdx.app.getType() == Application.ApplicationType.Desktop) {
characterComponent.walkDirection.scl(10f * delta); //Vitesse Déplacement Personnage
}
characterComponent.characterController.setWalkDirection(characterComponent.walkDirection);
ghost = new Matrix4();
translation = new Vector3();
characterComponent.ghostObject.getWorldTransform(ghost);
ghost.getTranslation(translation);
modelComponent.instance.transform.set(translation.x, translation.y, translation.z, camera.direction.x, camera.direction.y, camera.direction.z, 0);
//BodyParts movement
hair.getComponent(PlayerModelComponent.class).instance.transform.set(translation.x, translation.y, translation.z, camera.direction.x, camera.direction.y, camera.direction.z, 0);
ear.getComponent(PlayerModelComponent.class).instance.transform.set(translation.x, translation.y, translation.z, camera.direction.x, camera.direction.y, camera.direction.z, 0);
mouth.getComponent(PlayerModelComponent.class).instance.transform.set(translation.x, translation.y, translation.z, camera.direction.x, camera.direction.y, camera.direction.z, 0);
scar.getComponent(PlayerModelComponent.class).instance.transform.set(translation.x, translation.y, translation.z, camera.direction.x, camera.direction.y, camera.direction.z, 0);
float offsetx = 2;
float offsetz = 2;
camera.position.set(translation.x+offsetx, translation.y, translation.z+offsetz);
camera.lookAt(translation.x, translation.y, translation.z);
什么是开始的想法 正如您在下面的示例中看到的那样,我尝试偏移凸轮位置,但不是我应该的那样,离最终机制不远,但没有我想要的那么近, 有人可以帮忙吗?