Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle arrow shooting (#101) #121

Merged
merged 11 commits into from
Sep 9, 2019

Conversation

aramperes
Copy link
Contributor

@aramperes aramperes commented Sep 8, 2019

#101

  • Handle digging status for using bow
  • Find arrow stack and consume in Survival/Adventure
  • Submit event for shooting arrow with given position
  • Implement Arrow entity
  • Spawn Arrow entity with velocity from player's rotation
  • Add tests

@codecov
Copy link

codecov bot commented Sep 8, 2019

Codecov Report

Merging #121 into develop will increase coverage by 0.79%.
The diff coverage is 87.03%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #121      +/-   ##
===========================================
+ Coverage    57.96%   58.76%   +0.79%     
===========================================
  Files           59       60       +1     
  Lines         8017     8230     +213     
===========================================
+ Hits          4647     4836     +189     
- Misses        3370     3394      +24
Impacted Files Coverage Δ
server/src/physics/component.rs 95.23% <0%> (+0.11%) ⬆️
core/src/network/packet/implementation.rs 0% <0%> (ø) ⬆️
core/src/entitymeta.rs 0% <0%> (ø) ⬆️
server/src/entity/broadcast.rs 92.96% <100%> (+0.72%) ⬆️
server/src/entity/mod.rs 100% <100%> (ø) ⬆️
server/src/util/mod.rs 86.79% <100%> (+1.07%) ⬆️
server/src/entity/types.rs 76.92% <100%> (+6.92%) ⬆️
server/src/entity/metadata.rs 73.52% <28.57%> (-5.16%) ⬇️
server/src/physics/entity.rs 74.61% <50%> (-2.25%) ⬇️
server/src/entity/arrow.rs 72% <72%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d9f9738...3746fc8. Read the comment docs.

@caelunshun
Copy link
Member

For spawning the arrow, I recommend adding a method to util::Spawner to lazily spawn it, as is done with items. This will avoid the need for tons of component accesses in the player digging system.

@aramperes
Copy link
Contributor Author

For spawning the arrow, I recommend adding a method to util::Spawner to lazily spawn it, as is done with items. This will avoid the need for tons of component accesses in the player digging system.

Yes, I was thinking of making a PlayerShootBowEvent, with a PlayerShootBowSystem listening for it. The system would then spawn the arrow using a function in Spawner similar to items. Does that seem right?

@caelunshun
Copy link
Member

Yes, that seems right. You might want to consider how you could generalize PlayerShootBowEvent to support other arrow shooting causes, such as dispensers.

@caelunshun
Copy link
Member

caelunshun commented Sep 8, 2019

Seems like the velocity is overflowing when being sent to clients.

@caelunshun caelunshun closed this Sep 8, 2019
@caelunshun caelunshun reopened this Sep 8, 2019
@caelunshun
Copy link
Member

Sorry, accidental close

@aramperes
Copy link
Contributor Author

So I'm not too sure, but it seems like the scale of velocity is very different for items and arrows. I packet-logged Spigot and saw velocity values in the thousands.

According to https://wiki.vg/Protocol#Entity_Velocity, it should be pretty normal to get very high velocity values since it's measured in 1/8000th of blocks per tick. Why the values are so much smaller for items is unclear to me.

@caelunshun
Copy link
Member

caelunshun commented Sep 9, 2019

The velocity value on Feather is in blocks per tick. The util::protocol_velocity function converts it to the units used for packets, 1/8000 block per tick, which is what you're observing.

@aramperes
Copy link
Contributor Author

aramperes commented Sep 9, 2019

The thing is util::protocol_velocity is performing the opposite conversion: dividing by 8000 is converting the protocol format (short) to blocks-per-tick (float). It should be multiplying the float values by 8000 to convert to short.

@caelunshun
Copy link
Member

caelunshun commented Sep 9, 2019

Ah... so protocol_velocity has always been incorrect, then. It should be multiplying by 8000. Sorry about that.

(Now I know what's causing entities to jitter on the client...)

@aramperes
Copy link
Contributor Author

I will merge develop into this branch and adjust the velocity.

@aramperes aramperes changed the title [WIP] Handle arrow shooting (#101) Handle arrow shooting (#101) Sep 9, 2019
@aramperes
Copy link
Contributor Author

Ready for review/merge.

server/src/entity/arrow.rs Outdated Show resolved Hide resolved
server/src/player/digging.rs Outdated Show resolved Hide resolved
@caelunshun
Copy link
Member

Also, physics aren't being applied to arrows on the server side because they don't have a bounding box (EntityPhysicsSystem joins over entities with bounding boxes). This can be observed by shooting an arrow and then rejoining; the arrow will be back to where it was shot from.

@aramperes
Copy link
Contributor Author

Also, physics aren't being applied to arrows on the server side because they don't have a bounding box (EntityPhysicsSystem joins over entities with bounding boxes). This can be observed by shooting an arrow and then rejoining; the arrow will be back to where it was shot from.

I added a bounding box and made the arrow spawn 1.5 blocks in front of the player. However, it seems like the arrow breaks off its course after a few blocks and falls down. Seems like something is off with the physics impl?

@caelunshun
Copy link
Member

Yes, physics::entity::drag_force returns 0 by default, so the velocity gets set to 0. gravitational_accelration should return -0.05 and drag_force 0.99 for arrows. I tried this, and it solved the problem.

@aramperes
Copy link
Contributor Author

Cool. Is there a value set for the "gliding" effect when the entity is blocked? Arrows should do a full-stop when colliding with a block.

@caelunshun
Copy link
Member

caelunshun commented Sep 9, 2019

That's not implemented yet, but you could just set slip_multiplier to 0.0 for arrows here. https://github.com/caelunshun/feather/blob/d9f973899e74f7816530e50f451da5b7592521a6/server/src/physics/entity.rs#L159

That won't work when the arrow hits a wall—only when it impacts the ground. A more robust solution would be to add an EntityCollideEvent and set arrows' velocities to 0 when the event is triggered. This will require some modification of the physics code, though.

@caelunshun
Copy link
Member

Thanks!

@caelunshun caelunshun merged commit 02dab41 into feather-rs:develop Sep 9, 2019
@aramperes aramperes deleted the feature/shoot-arrow branch September 9, 2019 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants