mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Make aiming more precise
This commit is contained in:
parent
e90f95bc75
commit
0912de2a26
@ -76,6 +76,8 @@ impl<'a> System<'a> for Sys {
|
||||
)
|
||||
})
|
||||
{
|
||||
controller.look_dir = target_pos.0 - pos.0;
|
||||
|
||||
let dist = Vec2::<f32>::from(target_pos.0 - pos.0).magnitude();
|
||||
if target_stats.is_dead {
|
||||
choose_new = true;
|
||||
|
@ -1,5 +1,7 @@
|
||||
use crate::{
|
||||
comp::{ActionState::*, CharacterState, ForceUpdate, HealthSource, Ori, Pos, Stats, Vel},
|
||||
comp::{
|
||||
ActionState::*, CharacterState, Controller, ForceUpdate, HealthSource, Ori, Pos, Stats, Vel,
|
||||
},
|
||||
state::{DeltaTime, Uid},
|
||||
};
|
||||
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
|
||||
@ -14,6 +16,7 @@ impl<'a> System<'a> for Sys {
|
||||
Read<'a, DeltaTime>,
|
||||
ReadStorage<'a, Pos>,
|
||||
ReadStorage<'a, Ori>,
|
||||
ReadStorage<'a, Controller>,
|
||||
WriteStorage<'a, Vel>,
|
||||
WriteStorage<'a, CharacterState>,
|
||||
WriteStorage<'a, Stats>,
|
||||
@ -28,6 +31,7 @@ impl<'a> System<'a> for Sys {
|
||||
dt,
|
||||
positions,
|
||||
orientations,
|
||||
controllers,
|
||||
mut velocities,
|
||||
mut character_states,
|
||||
mut stats,
|
||||
@ -35,7 +39,9 @@ impl<'a> System<'a> for Sys {
|
||||
): Self::SystemData,
|
||||
) {
|
||||
// Attacks
|
||||
for (entity, uid, pos, ori) in (&entities, &uids, &positions, &orientations).join() {
|
||||
for (entity, uid, pos, ori, controller) in
|
||||
(&entities, &uids, &positions, &orientations, &controllers).join()
|
||||
{
|
||||
let mut todo_end = false;
|
||||
|
||||
// Go through all other entities
|
||||
@ -53,11 +59,15 @@ impl<'a> System<'a> for Sys {
|
||||
)
|
||||
.join()
|
||||
{
|
||||
let dist = pos.0.distance(pos_b.0);
|
||||
|
||||
// Check if it is a hit
|
||||
if entity != b
|
||||
&& !stat_b.is_dead
|
||||
&& pos.0.distance_squared(pos_b.0) < 50.0
|
||||
&& ori.0.angle_between(pos_b.0 - pos.0).to_degrees() < 90.0
|
||||
&& dist < 6.0
|
||||
// TODO: Use size instead of 1.0
|
||||
// TODO: Implement eye levels
|
||||
&& controller.look_dir.angle_between(pos_b.0 - pos.0)) < (1.0 / dist).atan()
|
||||
{
|
||||
let dmg = if character_b.action.is_block()
|
||||
&& ori_b.0.angle_between(pos.0 - pos_b.0).to_degrees() < 90.0
|
||||
|
@ -69,6 +69,15 @@ impl<'a> System<'a> for Sys {
|
||||
character.movement = Stand;
|
||||
}
|
||||
|
||||
// Look
|
||||
if controller
|
||||
.look_dir
|
||||
.map(|n| !n.is_normal() || n.abs() < std::f32::EPSILON)
|
||||
.reduce_or()
|
||||
{
|
||||
controller.look_dir = controller.move_dir.into();
|
||||
}
|
||||
|
||||
// Glide
|
||||
if controller.glide
|
||||
&& !physics.on_ground
|
||||
|
@ -94,13 +94,7 @@ impl<'a> System<'a> for Sys {
|
||||
};
|
||||
|
||||
// Set direction based on move direction when on the ground
|
||||
let ori_dir = if controller
|
||||
.look_dir
|
||||
.map(|n| !n.is_normal() || n.abs() < std::f32::EPSILON)
|
||||
.reduce_or()
|
||||
|| character.movement == Glide
|
||||
|| character.movement.is_roll()
|
||||
{
|
||||
let ori_dir = if character.movement == Glide || character.movement.is_roll() {
|
||||
Vec2::from(vel.0)
|
||||
} else {
|
||||
Vec2::from(controller.look_dir).normalized()
|
||||
|
Loading…
Reference in New Issue
Block a user