Closed davcri closed 7 years ago
Personally I don't believe this improvement is needed. While it fixes the issue you were having, the project by default does not have movement and thus would not need this bug fixed. As it stands, this only really serves to increase the processing power needed to run this tutorial at 60fps (even if not by much).
However, if we really do want this explained, I could suggest that we simply document this behavior using some comments in the code rather than move it to the process function. It would prevent users who came from the YouTube video from getting confused with the discrepancy, while still improving the tutorial. :)
Just my opinion though - ultimately it's Nathan's decision whether this is needed or not.
Thank you for your work, but I agree with @LikeLakers2 here, it's intended. Or rather movement was not intended. If you change the code from a video tutorial it will confuse viewers. Don't hesitate to message me before you create a PR like this - I'll tell you if it's worth going the extra mile or not.
I understand that changing the code would confuse viewers. I vote for the comment in code!
Don't hesitate to message me before you create a PR like this - I'll tell you if it's worth going the extra mile or not.
Ok got it ;) Anyway for me there is no problem in creating PR (I will tinker with code anyway 😛 ), also if they get refused. In the end we need to discuss about a topic, and I found markdown syntax very handy in this cases.
A note on performance: it's true that they can be improved by calculating, in Player.gd
, the direction_from_player
only if the player is inside the DETECT_RADIUS
:
var detect_count = 0
for node in get_tree().get_nodes_in_group('detectable'):
if pos.distance_to(node.pos) < DETECT_RADIUS:
var direction_from_player = (node.get_pos() - pos).normalized()
var angle_to_node = rad2deg(direction.angle_to(direction_from_player))
if abs(angle_to_node) < FOV/2:
detect_count += 1
In this PR I didn't do this because it changes object's responsibilities
In the video [...] How to code a Field of View in Godot a field of view mechianic is implemented.
I added movement to the player and discovered this strange behaviour:
This happens because
direction_from_player
gets assigned only once in the_ready()
function of every Object node.Calculating this value in the game loop fixes this behaviour: