-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Implement player:get_point_dir() and player:get_point_screen_pos() #15567
base: master
Are you sure you want to change the base?
Conversation
I'm only now realizing how useful this would be for mobile compatibility. Think hitting enemies with a weapon that is supposed to depend on distance in some way. You have no reliable way to detect the distance currently, because simple position difference length doesn't account for collision boxes for example. This would allow to at least do a raycast along the actual strike direction (because doing it along look direction would break mobile compatibility), find intersection position, and get distance as position difference length from that to player "eyes". |
Practical example? |
Some movable crosshair? |
A crosshair-like HUD or a "what am I looking at" HUD text like the one in NodeCore (currently that one is placed next to the crosshair afaik, once it takes the actual pointing direction into account, it should also be placed next to the actual pointer position). |
This PR implements
player:get_point_dir()
as described in #15562More design decision explanation in addition to the issue:
I chose yaw/pitch for the internal representation / for the network protocol because this means we only need two floats, a normal vector would need three and a quaternion four
After a discussion with Warr1024, I've also added
player:get_point_screen_pos()
so that games can place HUD elements taking the pointer position into account.To do
This PR is a Ready for Review.
I'm no expert in this rotation business, but the rotation stuff works and makes sense as far as I can tell. EDIT: The more complicated rotation stuff I was doing in the first version of this PR doesn't exist anymore.
How to test
Some quick example code for testing
player:get_point_screen_pos()
Install GGraffiti with a patch to use
player:get_point_dir()
: grorp/ggraffiti@1eed15ctouch_use_crosshair = true
touch_use_crosshair = false
: You will now paint where you put your fingerAlso verify that things still work correctly with non-zero eye offset (
player:set_eye_offset
)