Improve head swivel code #4622
No reviewers
Labels
No Label
#P1 CRITICAL
#P2: HIGH
#P3: elevated
#P4 priority: medium
#P6: low
#Review
annoying
API
bug
code quality
combat
commands
compatibility
configurability
contribution inside
controls
core feature
creative mode
delayed for engine release
documentation
duplicate
enhancement
environment
feature request
gameplay
graphics
ground content conflict
GUI/HUD
help wanted
incomplete feature
invalid / won't fix
items
looking for contributor
mapgen
meta
mineclone2+
Minecraft >= 1.13
Minecraft >= 1.17
missing feature
mobile
mobs
mod support
model needed
multiplayer
Needs adoption
needs discussion
needs engine change
needs more information
needs research
nodes
non-mob entities
performance
player
possible close
redstone
release notes
schematics
Skyblock
sounds
Testing / Retest
tools
translation
unconfirmed
mcl5
mcla
Media missing
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
No due date set.
Blocks
#4479 Improve mob smartness (cliffs, paths) part 1
VoxeLibre/VoxeLibre
Reference: VoxeLibre/VoxeLibre#4622
Loading…
Reference in New Issue
No description provided.
Delete Branch "head-swivel"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Use the minetest 5.9.0 API that uses radians not degree.
Simplify computations to make this more efficient, in particular by querying and updating the bone position less frequently.
Resolves minetest warning
Deprecated call to set_bone_position, use set_bone_override instead
in this location, but other uses remain.I chose to not modify
mcl_util.set_bone_position
because it redundantly compares to the previous rotation once more.8f427042a3
to5267fdcf9d
Improve head swivel code.to Improve head swivel codeAccording to this comment, this has a (positive) performance impact to reduce the calls to get_bone:
https://codeberg.org/mineclonia/mineclonia/pulls/1992#issuecomment-2274316
5267fdcf9d
toe212280753
Currently Mineclonia currently officially support Minetest version 5.6.0. We should probably update that to 5.7.0 about now since 5.9.0 was released. I do however think it is too early to use features from 5.9.0. Can you remove them from the PR? You can put them into another PR but it will probably be a year or so until it we can merge it.
Many servers still run <5.9.0 and people install the game on older clients using ContentDB.
Edit: Posted on the wrong issue tracker :)
For previous version
if self.object.get_bone_override then -- minetest >= 5.9
will detect them and use the old method. So this is supposed to be portable (but I did not test):self.object:set_bone_position(self.head_swivel, newp, vector.apply(newr, math.deg))
e212280753
to3537814a16
3537814a16
toef1facbeda
Pushed a bug fix for the <5.9 branch.
@ -331,3 +324,1 @@
if chance < 1 then chance = 1 end
local look_at_player_chance = math.random(chance)
local look_at_player_chance = math.random(math.max(1,150/self.curiosity))
Is this correct usage of
math.random
, considering #4621?I believe the integer rounding is intended here, as the value is compared using
look_at_player_chance == 1
below. Sheep have curiosity 6, so this will bemath.random(25)
.It could probably be improved/simplified to something like
I tested this under 5.8, seems to work fine. Not sure what could break here.
However, some of our mobs just don't have head swivel support in their models. I remember having weird issues when doing rovers and stalkers, and eventually skipped this part. Those not working are obviously not regressions and shouldn't stall this PR.
ef1facbeda
toc1dc9d401c
updated, but did not test curiosity yet.
Curiosity meaning may be skewed, if it's configured properly for the various mobs, it may be out of scope for this PR. If it isn't... well, could as well reverse it.
Otherwise code LGTM.
@ -307,3 +304,2 @@
-- was 10000 - div by 12 for avg entities as outside loop
local stop_look_at_player = stop_look_at_player_chance == 1
local stop_look_at_player = math.random() * 833 <= self.curiosity
Or should it be
>=
? As it is, the higher "curiosity", the lower the chance to look at the player...?I believe the motivation is that a more curious entity also loses interest faster.
@ -348,0 +322,4 @@
-- but frequency of check isn't good as it is costly. Making others too infrequent requires testing
-- was 5000 but called in loop based on entities. so div by 12 as estimate avg of entities found,
-- then div by 20 as less freq lookup
if math.random() * 150 <= self.curiosity then
Same thing here?
Seems fine to me: A more curious entity should start looking at the player more often.
Code is fine then, needs testing only.
c1dc9d401c
to2e5b0bb3c7
I am somewhat troubled that the entire
eye_height
logic in the existing code is somewhat odd. If you look at the mobs, they often have very weird eye_height values:I believe there might be a sign error somewhere in these computations, and these values were manually adjusted to "look good" rather than by fixing the math. Just consider axolotl and chicken: -0.5 vs. 1.5? why?
Well, the rest don't look that off though.
@the-real-herowl llama at 3, blaze with 3.5? even villagers clearly are not 2.2 blocks tall.
Looks good to me from my testing. The only thing I'd comment is their heads seem to switch back-and-forth from looking at you to looking forward a bit too rapidly.
We currently do not have a "smooth swivel" functionality in yet. I opened #4698 for this.