mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'zesterer/small-fixes' into 'master'
Collision fixes, better camera in build mode See merge request veloren/veloren!416
This commit is contained in:
commit
8b4b1163d4
@ -146,8 +146,10 @@ impl<'a> System<'a> for Sys {
|
|||||||
for _ in 0..increments as usize {
|
for _ in 0..increments as usize {
|
||||||
pos.0 += pos_delta / increments;
|
pos.0 += pos_delta / increments;
|
||||||
|
|
||||||
|
const MAX_ATTEMPTS: usize = 16;
|
||||||
|
|
||||||
// While the player is colliding with the terrain...
|
// While the player is colliding with the terrain...
|
||||||
while collision_with(pos.0, near_iter.clone()) && attempts < 16 {
|
while collision_with(pos.0, near_iter.clone()) && attempts < MAX_ATTEMPTS {
|
||||||
// Calculate the player's AABB
|
// Calculate the player's AABB
|
||||||
let player_aabb = Aabb {
|
let player_aabb = Aabb {
|
||||||
min: pos.0 + Vec3::new(-player_rad, -player_rad, 0.0),
|
min: pos.0 + Vec3::new(-player_rad, -player_rad, 0.0),
|
||||||
@ -180,9 +182,11 @@ impl<'a> System<'a> for Sys {
|
|||||||
})
|
})
|
||||||
// Find the maximum of the minimum collision axes (this bit is weird, trust me that it works)
|
// Find the maximum of the minimum collision axes (this bit is weird, trust me that it works)
|
||||||
.max_by_key(|(_, block_aabb)| {
|
.max_by_key(|(_, block_aabb)| {
|
||||||
((player_aabb.collision_vector_with_aabb(*block_aabb) / vel.0)
|
((player_aabb
|
||||||
|
.collision_vector_with_aabb(*block_aabb)
|
||||||
.map(|e| e.abs())
|
.map(|e| e.abs())
|
||||||
.reduce_partial_min()
|
.product()
|
||||||
|
+ block_aabb.min.z)
|
||||||
* 1_000_000.0) as i32
|
* 1_000_000.0) as i32
|
||||||
})
|
})
|
||||||
.expect("Collision detected, but no colliding blocks found!");
|
.expect("Collision detected, but no colliding blocks found!");
|
||||||
@ -240,6 +244,11 @@ impl<'a> System<'a> for Sys {
|
|||||||
|
|
||||||
attempts += 1;
|
attempts += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if attempts == MAX_ATTEMPTS {
|
||||||
|
pos.0 = old_pos;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if on_ground {
|
if on_ground {
|
||||||
|
@ -127,8 +127,18 @@ impl Scene {
|
|||||||
// Alter camera position to match player.
|
// Alter camera position to match player.
|
||||||
let tilt = self.camera.get_orientation().y;
|
let tilt = self.camera.get_orientation().y;
|
||||||
let dist = self.camera.get_distance();
|
let dist = self.camera.get_distance();
|
||||||
|
let up = if client
|
||||||
|
.state()
|
||||||
|
.read_storage::<comp::CanBuild>()
|
||||||
|
.get(client.entity())
|
||||||
|
.is_some()
|
||||||
|
{
|
||||||
|
1.5
|
||||||
|
} else {
|
||||||
|
1.2
|
||||||
|
};
|
||||||
self.camera.set_focus_pos(
|
self.camera.set_focus_pos(
|
||||||
player_pos + Vec3::unit_z() * (1.2 + dist * 0.15 - tilt.min(0.0) * dist * 0.75),
|
player_pos + Vec3::unit_z() * (up + dist * 0.15 - tilt.min(0.0) * dist * 0.75),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Tick camera for interpolation.
|
// Tick camera for interpolation.
|
||||||
|
Loading…
Reference in New Issue
Block a user