我用Bevy制作了一个3d迷宫,但当我试图在迷宫中导航时,相机可以透过墙壁看到东西。往下看一条走廊,前面的墙就会出现,但当它越来越近时,它就会被切断,我可以透过它看到另一条走廊。
我将Box精灵用于墙壁,如下所示:
commands
.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Box::new(1.0, 1.0, 0.1))),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
transform: Transform::from_translation(Vec3::new(x, 0.5, y+0.5)),
..Default::default()
});我的相机是这样添加的:
commands
.spawn(Camera3dBundle {
transform: Transform::from_translation(Vec3::new(-2.0, 0.5, 0.0))
.looking_at(Vec3::new(0.0, 0.5, 0.0), Vec3::unit_y()),
..Default::default()
})为了防止透视图看得太近,我需要对透视图做什么额外的操作吗?理想情况下,它永远不会看透物体。
发布于 2021-01-02 17:56:31
原来我的墙壁恰好相隔1个单位,默认的近场透视是1.0。将摄影机上透视的near参数减小到0.01可防止在距离墙太近时透过墙进行透视。
在main.rs中:
use bevy_render::camera::PerspectiveProjection;
commands
.spawn(Camera3dBundle {
transform: Transform::from_translation(Vec3::new(-2.0, 0.5, 0.0))
.looking_at(Vec3::new(0.0, 0.5, 0.0), Vec3::unit_y()),
perspective_projection: PerspectiveProjection {
near: 0.01,
..Default::default()
},
..Default::default()
})在cargo.toml中:
[dependencies]
bevy_render = "0.4"https://stackoverflow.com/questions/65528305
复制相似问题