Added better terrain collisions

Former-commit-id: 38de44654d8050260a19a1da6c40c0f701602f13
This commit is contained in:
Joshua Barretto 2019-04-24 12:17:45 +01:00
parent f210de09df
commit 9105bf0811
2 changed files with 13 additions and 8 deletions

View File

@ -29,13 +29,16 @@ impl<'a> System<'a> for Sys {
pos.0 += vel.0 * dt.0 as f32;
// Basic collision with terrain
let mut i = 0;
while terrain
.get(pos.0.map(|e| e as i32))
.map(|vox| !vox.is_empty())
.unwrap_or(false)
.unwrap_or(false) &&
i < 20
{
pos.0.z += 0.05;
pos.0.z += 0.01;
vel.0.z = 0.0;
i += 1;
}
}
}

View File

@ -54,6 +54,8 @@ impl<M> Meshable for Dyna<Block, M> {
.filter(|pos| pos.map(|e| e >= 1).reduce_and())
.filter(|pos| pos.map2(self.get_size(), |e, sz| e < sz as i32 - 1).reduce_and())
{
let offs = pos.map(|e| e as f32 - 1.0);
if let Some(col) = self
.get(pos)
.ok()
@ -67,9 +69,9 @@ impl<M> Meshable for Dyna<Block, M> {
.unwrap_or(true)
{
mesh.push_quad(create_quad(
-Vec3::one() + pos.map(|e| e as f32) + Vec3::unit_y(),
-Vec3::unit_y(),
offs,
Vec3::unit_z(),
Vec3::unit_y(),
-Vec3::unit_x(),
col,
));
@ -80,7 +82,7 @@ impl<M> Meshable for Dyna<Block, M> {
.unwrap_or(true)
{
mesh.push_quad(create_quad(
-Vec3::one() + pos.map(|e| e as f32) + Vec3::unit_x(),
offs + Vec3::unit_x(),
Vec3::unit_y(),
Vec3::unit_z(),
Vec3::unit_x(),
@ -106,7 +108,7 @@ impl<M> Meshable for Dyna<Block, M> {
.unwrap_or(true)
{
mesh.push_quad(create_quad(
-Vec3::one() + pos.map(|e| e as f32) + Vec3::unit_y(),
offs + Vec3::unit_y(),
Vec3::unit_z(),
Vec3::unit_x(),
Vec3::unit_y(),
@ -119,7 +121,7 @@ impl<M> Meshable for Dyna<Block, M> {
.unwrap_or(true)
{
mesh.push_quad(create_quad(
-Vec3::one() + pos.map(|e| e as f32),
offs,
Vec3::unit_y(),
Vec3::unit_x(),
-Vec3::unit_z(),
@ -132,7 +134,7 @@ impl<M> Meshable for Dyna<Block, M> {
.unwrap_or(true)
{
mesh.push_quad(create_quad(
-Vec3::one() + pos.map(|e| e as f32) + Vec3::unit_z(),
offs + Vec3::unit_z(),
Vec3::unit_x(),
Vec3::unit_y(),
Vec3::unit_z(),