mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-26 21:58:20 -06:00
pass velocity to server move evt
This commit is contained in:
parent
bc3db2c95e
commit
81decc6202
|
@ -2,8 +2,7 @@ use shipyard::{Component, View, ViewMut, EntitiesViewMut, IntoIter, track};
|
||||||
use glam::{IVec3, Quat, Vec3};
|
use glam::{IVec3, Quat, Vec3};
|
||||||
use kubi_shared::block::Block;
|
use kubi_shared::block::Block;
|
||||||
use crate::{
|
use crate::{
|
||||||
player::MainPlayer,
|
client_physics::ClPhysicsActor, player::MainPlayer, transform::Transform
|
||||||
transform::Transform
|
|
||||||
};
|
};
|
||||||
use super::EventComponent;
|
use super::EventComponent;
|
||||||
|
|
||||||
|
@ -11,6 +10,8 @@ use super::EventComponent;
|
||||||
pub enum PlayerActionEvent {
|
pub enum PlayerActionEvent {
|
||||||
PositionChanged {
|
PositionChanged {
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
|
//XXX: should this even be here?
|
||||||
|
velocity: Vec3,
|
||||||
direction: Quat
|
direction: Quat
|
||||||
},
|
},
|
||||||
UpdatedBlock {
|
UpdatedBlock {
|
||||||
|
@ -22,14 +23,17 @@ pub enum PlayerActionEvent {
|
||||||
pub fn generate_move_events(
|
pub fn generate_move_events(
|
||||||
transforms: View<Transform, track::All>,
|
transforms: View<Transform, track::All>,
|
||||||
player: View<MainPlayer>,
|
player: View<MainPlayer>,
|
||||||
|
actors: View<ClPhysicsActor>,
|
||||||
mut entities: EntitiesViewMut,
|
mut entities: EntitiesViewMut,
|
||||||
mut events: ViewMut<EventComponent>,
|
mut events: ViewMut<EventComponent>,
|
||||||
mut actions: ViewMut<PlayerActionEvent>,
|
mut actions: ViewMut<PlayerActionEvent>,
|
||||||
) {
|
) {
|
||||||
let Some((_, transform)) = (&player, transforms.inserted_or_modified()).iter().next() else { return };
|
let Some((_, transform, actor)) = (&player, transforms.inserted_or_modified(), &actors).iter().next() else { return };
|
||||||
let (_, direction, position) = transform.0.to_scale_rotation_translation();
|
let (_, direction, position) = transform.0.to_scale_rotation_translation();
|
||||||
|
//HACK: if the actor is disabled, the velocity is irrelevant, so we just set it to zero.
|
||||||
|
let velocity = if actor.disable { Vec3::ZERO } else { actor.velocity };
|
||||||
entities.add_entity(
|
entities.add_entity(
|
||||||
(&mut events, &mut actions),
|
(&mut events, &mut actions),
|
||||||
(EventComponent, PlayerActionEvent::PositionChanged { position, direction })
|
(EventComponent, PlayerActionEvent::PositionChanged { position, velocity, direction })
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,13 @@ pub fn send_player_movement_events(
|
||||||
mut client: UniqueViewMut<UdpClient>,
|
mut client: UniqueViewMut<UdpClient>,
|
||||||
) {
|
) {
|
||||||
for event in actions.iter() {
|
for event in actions.iter() {
|
||||||
let PlayerActionEvent::PositionChanged { position, direction } = event else {
|
let PlayerActionEvent::PositionChanged { position, velocity, direction } = event else {
|
||||||
continue
|
continue
|
||||||
};
|
};
|
||||||
client.0.send(
|
client.0.send(
|
||||||
postcard::to_allocvec(&ClientToServerMessage::PositionChanged {
|
postcard::to_allocvec(&ClientToServerMessage::PositionChanged {
|
||||||
position: *position,
|
position: *position,
|
||||||
velocity: Vec3::ZERO,
|
velocity: *velocity,
|
||||||
direction: *direction
|
direction: *direction
|
||||||
}).unwrap().into_boxed_slice(),
|
}).unwrap().into_boxed_slice(),
|
||||||
Channel::Move as usize,
|
Channel::Move as usize,
|
||||||
|
|
Loading…
Reference in a new issue