M client/src/index.ts => client/src/index.ts +1 -1
@@ 224,4 224,4 @@ function planet_type_to_tex_id(ty: PlanetType): string {
return "earth.png"
}
return "unknown.png"
-}>
\ No newline at end of file
+}
M server/src/handler.rs => server/src/handler.rs +6 -4
@@ 6,8 6,8 @@ use futures::stream::{SplitSink, SplitStream};
use futures::{FutureExt, SinkExt, StreamExt};
use hyper::upgrade::Upgraded;
use log::{debug, error, info};
-use nalgebra::vector;
-use rapier2d_f64::prelude::{RigidBodyBuilder, RigidBodyType, ColliderBuilder};
+use nalgebra::{vector, point};
+use rapier2d_f64::prelude::{RigidBodyBuilder, RigidBodyType, ColliderBuilder, MassProperties};
use tokio::sync::RwLock;
use tokio::sync::mpsc::Receiver;
use tokio_tungstenite::WebSocketStream;
@@ 140,7 140,10 @@ pub async fn handle_client(mgr: ClientManager, data: Arc<RwLock<PhysicsData>>, r
let player_body = RigidBodyBuilder::new(RigidBodyType::Dynamic)
.translation(vector![0.0, 2100.0/SCALE])
.build();
- let player_collider = ColliderBuilder::cuboid(25.0 / SCALE, 25.0 / SCALE).build();
+ let player_collider = ColliderBuilder::cuboid(25.0 / SCALE, 25.0 / SCALE)
+ //.mass_properties(MassProperties::new(point![0.0, 0.0], 75.0, 2000.0))
+ .mass(75.0)
+ .build();
let player_handle = rigid_body_set.insert(player_body);
collider_set.insert_with_parent(player_collider, player_handle, &mut rigid_body_set);
@@ 207,7 210,6 @@ pub async fn handle_client(mgr: ClientManager, data: Arc<RwLock<PhysicsData>>, r
me.input.down = p.down_pressed;
me.input.left = p.left_pressed;
me.input.right = p.right_pressed;
- debug!("{} {} {} {}", me.input.up, me.input.down, me.input.left, me.input.right);
}
}
}
M server/src/planet.rs => server/src/planet.rs +1 -1
@@ 6,7 6,7 @@ use starkingdoms_protocol::planet::PlanetType;
use crate::{SCALE, manager::ClientHandlerMessage};
//const GRAVITY: f64 = 0.001;
-const GRAVITY: f64 = 6.6674;
+const GRAVITY: f64 = 12.6674;
#[derive(Clone)]
pub struct Planet {
M server/src/timer.rs => server/src/timer.rs +68 -11
@@ 1,13 1,13 @@
use std::{time::Duration, sync::Arc};
use log::{debug, error};
-use nalgebra::vector;
+use nalgebra::{vector, point, Vector2};
use rapier2d_f64::prelude::{PhysicsPipeline};
use tokio::{time::sleep, sync::RwLock};
use starkingdoms_protocol::player::Player;
use crate::{manager::{ClientHandlerMessage, ClientManager, PhysicsData}, SCALE, planet::Planets};
-pub const ROTATIONAL_FORCE: f64 = 100.0;
-pub const LATERAL_FORCE: f64 = 100.0;
+pub const ROTATIONAL_FORCE: f64 = 200.0;
+pub const LATERAL_FORCE: f64 = 80.0;
pub async fn timer_main(mgr: ClientManager, physics_data: Arc<RwLock<PhysicsData>>, world_data: Arc<RwLock<Planets>>) {
let mut pipeline = PhysicsPipeline::new();
@@ 23,38 23,95 @@ pub async fn timer_main(mgr: ClientManager, physics_data: Arc<RwLock<PhysicsData
let mut physics_data = physics_data.write().await;
let player_handle = player.handle;
let player_body = physics_data.rigid_body_set.get_mut(player_handle).unwrap();
+ player_body.reset_forces(true);
+ player_body.reset_torques(true);
let planets = world_data.read().await;
let grav_force = planets.gravity((player_body.translation().x, player_body.translation().y), player_body.mass());
- player_body.add_force(vector![grav_force.0, grav_force.1], true);
+ player_body.apply_impulse(vector![grav_force.0, grav_force.1], true);
let mut torque = 0.0;
+ let mut left_top_thruster: f64 = 0.0;
+ let mut right_top_thruster: f64 = 0.0;
+ let mut left_bottom_thruster: f64 = 0.0;
+ let mut right_bottom_thruster: f64 = 0.0;
if player.input.right {
torque += ROTATIONAL_FORCE;
+ left_top_thruster -= 1.0;
+ right_bottom_thruster += 1.0;
}
if player.input.left {
torque -= ROTATIONAL_FORCE;
+ right_top_thruster -= 1.0;
+ left_bottom_thruster += 1.0;
}
- player_body.add_torque(torque, true);
+ //player_body.apply_torque_impulse(torque, true);
let mut lateral = vector![0.0, 0.0];
if player.input.up {
lateral -= vector![0.0, LATERAL_FORCE];
+ left_bottom_thruster -= 1.0;
+ right_bottom_thruster -= 1.0;
}
if player.input.down {
lateral += vector![0.0, LATERAL_FORCE];
+ left_top_thruster += 1.0;
+ right_top_thruster += 1.0;
}
+ left_top_thruster = LATERAL_FORCE * left_top_thruster.clamp(-1.0, 1.0);
+ right_top_thruster = LATERAL_FORCE * right_top_thruster.clamp(-1.0, 1.0);
+ left_bottom_thruster = LATERAL_FORCE * left_bottom_thruster.clamp(-1.0, 1.0);
+ right_bottom_thruster = LATERAL_FORCE * right_bottom_thruster.clamp(-1.0, 1.0);
let rotation = player_body.rotation().clone().angle();
-
- let lateral_rotated = vector![
- lateral.x * rotation.cos() - lateral.y * rotation.sin(),
- lateral.x * rotation.sin() + lateral.y * rotation.cos()
+ let left_top_thruster = vector![
+ -left_top_thruster * rotation.sin(),
+ left_top_thruster * rotation.cos()
];
-
- player_body.add_force(lateral_rotated, true);
+ let right_top_thruster = vector![
+ -right_top_thruster * rotation.sin(),
+ right_top_thruster * rotation.cos()
+ ];
+ let left_bottom_thruster = vector![
+ -left_bottom_thruster * rotation.sin(),
+ left_bottom_thruster * rotation.cos()
+ ];
+ let right_bottom_thruster = vector![
+ -right_bottom_thruster * rotation.sin(),
+ right_bottom_thruster * rotation.cos()
+ ];
+ let scale = SCALE as f64;
+ let top_left_point = point![
+ -25. / scale * rotation.cos() +25. / scale * rotation.sin(),
+ -25. / scale * rotation.sin() -25. / scale * rotation.cos()
+ ] + player_body.translation();
+ let top_right_point = point![
+ 25. / scale * rotation.cos() +25. / scale * rotation.sin(),
+ 25. / scale * rotation.sin() -25. / scale * rotation.cos()
+ ] + player_body.translation();
+ let bottom_left_point = point![
+ -25. / scale * rotation.cos() -25. / scale * rotation.sin(),
+ -25. / scale * rotation.sin() +25. / scale * rotation.cos()
+ ] + player_body.translation();
+ let bottom_right_point = point![
+ 25. / scale * rotation.cos() -25. / scale * rotation.sin(),
+ 25. / scale * rotation.sin() +25. / scale * rotation.cos()
+ ] + player_body.translation();
+
+ player_body.add_force_at_point(
+ left_top_thruster,
+ top_left_point, true);
+ player_body.add_force_at_point(
+ right_top_thruster,
+ top_right_point, true);
+ player_body.add_force_at_point(
+ left_bottom_thruster,
+ bottom_left_point, true);
+ player_body.add_force_at_point(
+ right_bottom_thruster,
+ bottom_right_point, true);
let translation = player_body.translation();
M spacetime_py/__pycache__/ninja_syntax.cpython-310.pyc => spacetime_py/__pycache__/ninja_syntax.cpython-310.pyc +0 -0