mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-26 05:38:20 -06:00
uwu
This commit is contained in:
parent
1b87553f79
commit
c799d94e0a
|
@ -23,15 +23,17 @@ impl Default for GlobalClPhysicsConfig {
|
||||||
|
|
||||||
//TODO: actors should be represented by a vertical line, not a point.
|
//TODO: actors should be represented by a vertical line, not a point.
|
||||||
//XXX: maybe a capsule? (or configurable hull?)
|
//XXX: maybe a capsule? (or configurable hull?)
|
||||||
|
//TODO: per block friction
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct ClPhysicsActor {
|
pub struct ClPhysicsActor {
|
||||||
pub disable: bool,
|
pub disable: bool,
|
||||||
pub offset: Vec3,
|
pub offset: Vec3,
|
||||||
pub forces: Vec3,
|
pub forces: Vec3,
|
||||||
|
pub constant_forces: Vec3,
|
||||||
pub velocity: Vec3,
|
pub velocity: Vec3,
|
||||||
pub terminal_velocity: f32,
|
pub terminal_velocity: f32,
|
||||||
//TODO: this should be configurable per block
|
pub decel: Vec3,
|
||||||
pub ground_friction: f32,
|
|
||||||
pub gravity_scale: f32,
|
pub gravity_scale: f32,
|
||||||
flag_ground: bool,
|
flag_ground: bool,
|
||||||
flag_collision: bool,
|
flag_collision: bool,
|
||||||
|
@ -42,6 +44,10 @@ impl ClPhysicsActor {
|
||||||
self.forces += force;
|
self.forces += force;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn apply_constant_force(&mut self, force: Vec3) {
|
||||||
|
self.constant_forces += force;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn on_ground(&self) -> bool {
|
pub fn on_ground(&self) -> bool {
|
||||||
self.flag_ground
|
self.flag_ground
|
||||||
}
|
}
|
||||||
|
@ -54,9 +60,11 @@ impl Default for ClPhysicsActor {
|
||||||
disable: false,
|
disable: false,
|
||||||
offset: vec3(0., 1.5, 0.),
|
offset: vec3(0., 1.5, 0.),
|
||||||
forces: Vec3::ZERO,
|
forces: Vec3::ZERO,
|
||||||
|
constant_forces: Vec3::ZERO,
|
||||||
velocity: Vec3::ZERO,
|
velocity: Vec3::ZERO,
|
||||||
terminal_velocity: 40.,
|
terminal_velocity: 40.,
|
||||||
ground_friction: 10.,
|
//constant deceleration, in ratio per second. e.g. value of 1 should stop the actor in 1 second.
|
||||||
|
decel: vec3(0., 0., 0.),
|
||||||
gravity_scale: 1.,
|
gravity_scale: 1.,
|
||||||
flag_ground: false,
|
flag_ground: false,
|
||||||
flag_collision: false,
|
flag_collision: false,
|
||||||
|
@ -145,16 +153,15 @@ pub fn update_client_physics_late(
|
||||||
}
|
}
|
||||||
|
|
||||||
//Apply velocity
|
//Apply velocity
|
||||||
actor_position += actor.velocity * dt.0.as_secs_f32();
|
actor_position += (actor.velocity + actor.constant_forces) * dt.0.as_secs_f32();
|
||||||
|
actor.constant_forces = Vec3::ZERO;
|
||||||
actor_position += actor.offset;
|
actor_position += actor.offset;
|
||||||
transform.0 = Mat4::from_scale_rotation_translation(scale, rotation.normalize(), actor_position);
|
transform.0 = Mat4::from_scale_rotation_translation(scale, rotation.normalize(), actor_position);
|
||||||
|
|
||||||
//Apply friction
|
//Apply "friction"
|
||||||
// if actor.flag_ground {
|
// let actor_velocity = actor.velocity;
|
||||||
// let actor_velocity = actor.velocity;
|
// let actor_decel = actor.decel;
|
||||||
// let actor_friction = actor.ground_friction;
|
// actor.velocity -= actor_velocity * actor_decel * dt.0.as_secs_f32();
|
||||||
// actor.velocity -= (actor_velocity * actor_friction * dt.0.as_secs_f32()) * vec3(1., 0., 1.);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
// for (_, mut transform) in (&controllers, &mut transforms).iter() {
|
// for (_, mut transform) in (&controllers, &mut transforms).iter() {
|
||||||
// let (scale, rotation, mut translation) = transform.0.to_scale_rotation_translation();
|
// let (scale, rotation, mut translation) = transform.0.to_scale_rotation_translation();
|
||||||
|
|
|
@ -86,12 +86,22 @@ fn update_movement(
|
||||||
let right = Vec2::from_angle(-euler.0).extend(0.).xzy();
|
let right = Vec2::from_angle(-euler.0).extend(0.).xzy();
|
||||||
let forward = Vec2::from_angle(-(euler.0 + PI/2.)).extend(0.).xzy();
|
let forward = Vec2::from_angle(-(euler.0 + PI/2.)).extend(0.).xzy();
|
||||||
|
|
||||||
actor.apply_force(ctl.speed * (
|
//TODO: remove hardcoded jump force
|
||||||
(forward * movement.z) +
|
// actor.apply_constant_force(ctl.speed * (
|
||||||
(right * movement.x) +
|
// (forward * movement.z) +
|
||||||
//TODO: remove hardcoded jump force
|
// (right * movement.x)
|
||||||
(Vec3::Y * movement.y * 125. * (actor_on_ground as u8 as f32))
|
// ));
|
||||||
));
|
actor.apply_force(
|
||||||
|
ctl.speed * (
|
||||||
|
(forward * movement.z) +
|
||||||
|
(right * movement.x)
|
||||||
|
) +
|
||||||
|
Vec3::Y * movement.y * 1250. * (actor_on_ground as u8 as f32)
|
||||||
|
);
|
||||||
|
|
||||||
|
// actor.decel =
|
||||||
|
// (right * (1. - inputs.movement.x.abs()) * 10.) +
|
||||||
|
// (forward * (1. - inputs.movement.y.abs()) * 10.);
|
||||||
|
|
||||||
// translation += forward * movement.z * ctl.speed * dt.0.as_secs_f32();
|
// translation += forward * movement.z * ctl.speed * dt.0.as_secs_f32();
|
||||||
// translation += right * movement.x * ctl.speed * dt.0.as_secs_f32();
|
// translation += right * movement.x * ctl.speed * dt.0.as_secs_f32();
|
||||||
|
|
Loading…
Reference in a new issue