mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fixed jumping inconsistencies, no block-snapping for ships
This commit is contained in:
committed by
Avi Weinstock
parent
8247c136bc
commit
e232a2e473
@ -20,17 +20,12 @@ pub type SiteId = u64;
|
|||||||
|
|
||||||
pub enum LocalEvent {
|
pub enum LocalEvent {
|
||||||
/// Applies upward force to entity's `Vel`
|
/// Applies upward force to entity's `Vel`
|
||||||
Jump(EcsEntity),
|
Jump(EcsEntity, f32),
|
||||||
/// Applies the `impulse` to `entity`'s `Vel`
|
/// Applies the `impulse` to `entity`'s `Vel`
|
||||||
ApplyImpulse {
|
ApplyImpulse {
|
||||||
entity: EcsEntity,
|
entity: EcsEntity,
|
||||||
impulse: Vec3<f32>,
|
impulse: Vec3<f32>,
|
||||||
},
|
},
|
||||||
/// Applies leaping force to `entity`'s `Vel` away from `wall_dir` direction
|
|
||||||
WallLeap {
|
|
||||||
entity: EcsEntity,
|
|
||||||
wall_dir: Vec3<f32>,
|
|
||||||
},
|
|
||||||
/// Applies `vel` velocity to `entity`
|
/// Applies `vel` velocity to `entity`
|
||||||
Boost { entity: EcsEntity, vel: Vec3<f32> },
|
Boost { entity: EcsEntity, vel: Vec3<f32> },
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ impl CharacterBehavior for Data {
|
|||||||
// They've climbed atop something, give them a boost
|
// They've climbed atop something, give them a boost
|
||||||
update
|
update
|
||||||
.local_events
|
.local_events
|
||||||
.push_front(LocalEvent::Jump(data.entity));
|
.push_front(LocalEvent::Jump(data.entity, BASE_JUMP_IMPULSE * 0.5));
|
||||||
}
|
}
|
||||||
update.character = CharacterState::Idle {};
|
update.character = CharacterState::Idle {};
|
||||||
return update;
|
return update;
|
||||||
|
@ -21,6 +21,7 @@ const BASE_HUMANOID_AIR_ACCEL: f32 = 2.0;
|
|||||||
const BASE_FLIGHT_ACCEL: f32 = 2.0;
|
const BASE_FLIGHT_ACCEL: f32 = 2.0;
|
||||||
const BASE_HUMANOID_WATER_ACCEL: f32 = 150.0;
|
const BASE_HUMANOID_WATER_ACCEL: f32 = 150.0;
|
||||||
const BASE_HUMANOID_WATER_SPEED: f32 = 180.0;
|
const BASE_HUMANOID_WATER_SPEED: f32 = 180.0;
|
||||||
|
pub const BASE_JUMP_IMPULSE: f32 = 16.0;
|
||||||
// const BASE_HUMANOID_CLIMB_ACCEL: f32 = 10.0;
|
// const BASE_HUMANOID_CLIMB_ACCEL: f32 = 10.0;
|
||||||
// const ROLL_SPEED: f32 = 17.0;
|
// const ROLL_SPEED: f32 = 17.0;
|
||||||
// const CHARGE_SPEED: f32 = 20.0;
|
// const CHARGE_SPEED: f32 = 20.0;
|
||||||
@ -181,10 +182,10 @@ impl Body {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn can_jump(&self) -> bool {
|
pub fn jump_impulse(&self) -> Option<f32> {
|
||||||
match self {
|
match self {
|
||||||
Body::Object(_) | Body::Ship(_) => false,
|
Body::Object(_) | Body::Ship(_) => None,
|
||||||
_ => true,
|
_ => Some(BASE_JUMP_IMPULSE),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -442,11 +443,12 @@ pub fn handle_jump(data: &JoinData, update: &mut StateUpdate) {
|
|||||||
.in_liquid
|
.in_liquid
|
||||||
.map(|depth| depth > 1.0)
|
.map(|depth| depth > 1.0)
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
&& data.body.can_jump()
|
&& data.body.jump_impulse().is_some()
|
||||||
{
|
{
|
||||||
update
|
update.local_events.push_front(LocalEvent::Jump(
|
||||||
.local_events
|
data.entity,
|
||||||
.push_front(LocalEvent::Jump(data.entity));
|
data.body.jump_impulse().unwrap(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use common::{
|
use common::{
|
||||||
comp::{
|
comp::{
|
||||||
body::ship::figuredata::VOXEL_COLLIDER_MANIFEST, BeamSegment, CharacterState, Collider,
|
body::ship::figuredata::VOXEL_COLLIDER_MANIFEST, BeamSegment, Body, CharacterState,
|
||||||
Gravity, Mass, Mounting, Ori, PhysicsState, Pos, PreviousPhysCache, Projectile, Scale,
|
Collider, Gravity, Mass, Mounting, Ori, PhysicsState, Pos, PreviousPhysCache, Projectile,
|
||||||
Shockwave, Sticky, Vel,
|
Scale, Shockwave, Sticky, Vel,
|
||||||
},
|
},
|
||||||
consts::{FRIC_GROUND, GRAVITY},
|
consts::{FRIC_GROUND, GRAVITY},
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
@ -85,6 +85,7 @@ pub struct PhysicsRead<'a> {
|
|||||||
beams: ReadStorage<'a, BeamSegment>,
|
beams: ReadStorage<'a, BeamSegment>,
|
||||||
shockwaves: ReadStorage<'a, Shockwave>,
|
shockwaves: ReadStorage<'a, Shockwave>,
|
||||||
char_states: ReadStorage<'a, CharacterState>,
|
char_states: ReadStorage<'a, CharacterState>,
|
||||||
|
bodies: ReadStorage<'a, Body>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(SystemData)]
|
#[derive(SystemData)]
|
||||||
@ -438,6 +439,7 @@ impl<'a> PhysicsData<'a> {
|
|||||||
positions,
|
positions,
|
||||||
velocities,
|
velocities,
|
||||||
orientations,
|
orientations,
|
||||||
|
read.bodies.maybe(),
|
||||||
&mut write.physics_states,
|
&mut write.physics_states,
|
||||||
previous_phys_cache,
|
previous_phys_cache,
|
||||||
!&read.mountings,
|
!&read.mountings,
|
||||||
@ -454,6 +456,7 @@ impl<'a> PhysicsData<'a> {
|
|||||||
pos,
|
pos,
|
||||||
vel,
|
vel,
|
||||||
_ori,
|
_ori,
|
||||||
|
body,
|
||||||
mut physics_state,
|
mut physics_state,
|
||||||
_previous_cache,
|
_previous_cache,
|
||||||
_,
|
_,
|
||||||
@ -502,6 +505,7 @@ impl<'a> PhysicsData<'a> {
|
|||||||
let mut tgt_pos = pos.0 + pos_delta;
|
let mut tgt_pos = pos.0 + pos_delta;
|
||||||
|
|
||||||
let was_on_ground = physics_state.on_ground;
|
let was_on_ground = physics_state.on_ground;
|
||||||
|
let block_snap = body.map_or(false, |body| body.jump_impulse().is_some());
|
||||||
|
|
||||||
match &collider {
|
match &collider {
|
||||||
Collider::Voxel { .. } => {
|
Collider::Voxel { .. } => {
|
||||||
@ -526,6 +530,7 @@ impl<'a> PhysicsData<'a> {
|
|||||||
Vec3::zero(),
|
Vec3::zero(),
|
||||||
&read.dt,
|
&read.dt,
|
||||||
was_on_ground,
|
was_on_ground,
|
||||||
|
block_snap,
|
||||||
|entity, vel| land_on_grounds.push((entity, vel)),
|
|entity, vel| land_on_grounds.push((entity, vel)),
|
||||||
);
|
);
|
||||||
tgt_pos = cpos.0;
|
tgt_pos = cpos.0;
|
||||||
@ -553,6 +558,7 @@ impl<'a> PhysicsData<'a> {
|
|||||||
Vec3::zero(),
|
Vec3::zero(),
|
||||||
&read.dt,
|
&read.dt,
|
||||||
was_on_ground,
|
was_on_ground,
|
||||||
|
block_snap,
|
||||||
|entity, vel| land_on_grounds.push((entity, vel)),
|
|entity, vel| land_on_grounds.push((entity, vel)),
|
||||||
);
|
);
|
||||||
tgt_pos = cpos.0;
|
tgt_pos = cpos.0;
|
||||||
@ -693,6 +699,7 @@ impl<'a> PhysicsData<'a> {
|
|||||||
ori_to.mul_direction(vel_other.0),
|
ori_to.mul_direction(vel_other.0),
|
||||||
&read.dt,
|
&read.dt,
|
||||||
was_on_ground,
|
was_on_ground,
|
||||||
|
block_snap,
|
||||||
|entity, vel| {
|
|entity, vel| {
|
||||||
land_on_grounds
|
land_on_grounds
|
||||||
.push((entity, Vel(ori_from.mul_direction(vel.0))))
|
.push((entity, Vel(ori_from.mul_direction(vel.0))))
|
||||||
@ -818,6 +825,7 @@ fn cylinder_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
|
|||||||
ground_vel: Vec3<f32>,
|
ground_vel: Vec3<f32>,
|
||||||
dt: &DeltaTime,
|
dt: &DeltaTime,
|
||||||
was_on_ground: bool,
|
was_on_ground: bool,
|
||||||
|
block_snap: bool,
|
||||||
mut land_on_ground: impl FnMut(Entity, Vel),
|
mut land_on_ground: impl FnMut(Entity, Vel),
|
||||||
) {
|
) {
|
||||||
let (radius, z_min, z_max) = cylinder;
|
let (radius, z_min, z_max) = cylinder;
|
||||||
@ -1062,15 +1070,7 @@ fn cylinder_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
|
|||||||
z_range.clone(),
|
z_range.clone(),
|
||||||
) && vel.0.z < 0.25
|
) && vel.0.z < 0.25
|
||||||
&& vel.0.z > -1.5
|
&& vel.0.z > -1.5
|
||||||
// && was_on_ground
|
&& block_snap
|
||||||
// && !collision_with(
|
|
||||||
// pos.0 - Vec3::unit_z() * 0.0,
|
|
||||||
// &terrain,
|
|
||||||
// |block| block.solid_height() >= (pos.0.z - 0.1).rem_euclid(1.0),
|
|
||||||
// near_iter.clone(),
|
|
||||||
// radius,
|
|
||||||
// z_range.clone(),
|
|
||||||
// )
|
|
||||||
{
|
{
|
||||||
let snap_height = terrain
|
let snap_height = terrain
|
||||||
.get(Vec3::new(pos.0.x, pos.0.y, pos.0.z - 0.1).map(|e| e.floor() as i32))
|
.get(Vec3::new(pos.0.x, pos.0.y, pos.0.z - 0.1).map(|e| e.floor() as i32))
|
||||||
|
@ -36,7 +36,6 @@ const DAY_CYCLE_FACTOR: f64 = 24.0 * 2.0;
|
|||||||
/// this value, the game's physics will begin to produce time lag. Ideally, we'd
|
/// this value, the game's physics will begin to produce time lag. Ideally, we'd
|
||||||
/// avoid such a situation.
|
/// avoid such a situation.
|
||||||
const MAX_DELTA_TIME: f32 = 1.0;
|
const MAX_DELTA_TIME: f32 = 1.0;
|
||||||
const HUMANOID_JUMP_ACCEL: f32 = 16.0;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct BlockChange {
|
pub struct BlockChange {
|
||||||
@ -454,13 +453,11 @@ impl State {
|
|||||||
let events = self.ecs.read_resource::<EventBus<LocalEvent>>().recv_all();
|
let events = self.ecs.read_resource::<EventBus<LocalEvent>>().recv_all();
|
||||||
for event in events {
|
for event in events {
|
||||||
let mut velocities = self.ecs.write_storage::<comp::Vel>();
|
let mut velocities = self.ecs.write_storage::<comp::Vel>();
|
||||||
let mut controllers = self.ecs.write_storage::<comp::Controller>();
|
|
||||||
let physics = self.ecs.read_storage::<comp::PhysicsState>();
|
let physics = self.ecs.read_storage::<comp::PhysicsState>();
|
||||||
match event {
|
match event {
|
||||||
LocalEvent::Jump(entity) => {
|
LocalEvent::Jump(entity, impulse) => {
|
||||||
if let Some(vel) = velocities.get_mut(entity) {
|
if let Some(vel) = velocities.get_mut(entity) {
|
||||||
vel.0.z = HUMANOID_JUMP_ACCEL
|
vel.0.z = impulse + physics.get(entity).map_or(0.0, |ps| ps.ground_vel.z);
|
||||||
+ physics.get(entity).map_or(0.0, |ps| ps.ground_vel.z);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
LocalEvent::ApplyImpulse { entity, impulse } => {
|
LocalEvent::ApplyImpulse { entity, impulse } => {
|
||||||
@ -468,21 +465,6 @@ impl State {
|
|||||||
vel.0 = impulse;
|
vel.0 = impulse;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
LocalEvent::WallLeap { entity, wall_dir } => {
|
|
||||||
if let (Some(vel), Some(_controller)) =
|
|
||||||
(velocities.get_mut(entity), controllers.get_mut(entity))
|
|
||||||
{
|
|
||||||
let hspeed = Vec2::<f32>::from(vel.0).magnitude();
|
|
||||||
if hspeed > 0.001 && hspeed < 0.5 {
|
|
||||||
vel.0 += vel.0.normalized()
|
|
||||||
* Vec3::new(1.0, 1.0, 0.0)
|
|
||||||
* HUMANOID_JUMP_ACCEL
|
|
||||||
* 1.5
|
|
||||||
- wall_dir * 0.03;
|
|
||||||
vel.0.z = HUMANOID_JUMP_ACCEL * 0.5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
LocalEvent::Boost {
|
LocalEvent::Boost {
|
||||||
entity,
|
entity,
|
||||||
vel: extra_vel,
|
vel: extra_vel,
|
||||||
|
Reference in New Issue
Block a user