Mob AI Issue and Possible Fix
#1
First, let me say that cuberite is an amazing server.  I especially like running it on my ancient android phone, it's performance is fantastic on such a limited platform.

But for as long as I have been messing around with it there is one problem that always keeps me from using it in a more serious manner, or for longer periods of time.

It's the Mob AI.  It's terrible.  The biggest problem to me, the one that always crops up and annoys me every time I make a server and build a house.  Is that the Mobs can see like superman.  They see you through walls, doors, hiding in a tree, underground.  If there is a mob within it's detection range then it knows exactly where you are and it swarms you regardless.

I use a minimap mod, that shows monster positions.  When underground I can move around and watch the Mobs on the surface follow me around.  It's crazy.

The main reason this is a problem is that you can't sleep in a bed while there are monsters around.  Which means you can't ever sleep in a bed for the most part.  because they swarm and collect around your house.

So I looked into the code and found a way to fix that one issue.  I added a check so that the Mob will only go into chase mode if it can actually see you.

Now, I'm not an experienced coder in c++ and I'm sure there is a way to make it better or nicer or proper or something. But I've been testing it on my phone server for a while now and it's been working great for me.  I haven't noticed any performance implications either, and this is a really old slow phone.

So I thought I would post my fix here and maybe someone who is a better coder than me can look at it and evaluate it and maybe integrate it into the source.

Thanks for your time and consideration.


~
Robert


https://pastebin.com/bf4AaMPz

Code:
diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp
index a904ac2da..1bf392e1a 100644
--- a/src/Mobs/AggressiveMonster.cpp
+++ b/src/Mobs/AggressiveMonster.cpp
@@ -38,13 +38,23 @@ void cAggressiveMonster::InStateChasing(std::chrono::milliseconds a_Dt, cChunk &

void cAggressiveMonster::EventSeePlayer(cPlayer * a_Player, cChunk & a_Chunk)
{
+
if (!a_Player->CanMobsTarget())
{
return;
}

- Super::EventSeePlayer(a_Player, a_Chunk);
- m_EMState = CHASING;
+ Vector3d MyHeadPosition1 = GetPosition() + Vector3d(0, GetHeight(), 0);
+ Vector3d TargetPosition1 = a_Player->GetPosition() + Vector3d(0, a_Player->GetHeight(), 0);
+ if (cLineBlockTracer::LineOfSightTrace(*GetWorld(), MyHeadPosition1, TargetPosition1, cLineBlockTracer::losAirWaterLava))
+ {
+ //LOGINFO("Mob Saw Player!");
+ Super::EventSeePlayer(a_Player, a_Chunk);
+ m_EMState = CHASING;
+ } else{
+ return;
+ }
+
}


Attached Files
.txt   AgressiveMonster.cpp.diff.txt (Size: 926 bytes / Downloads: 14)
Reply
Thanks given by:
#2
P.S. I copied most of this "fix" from another portion of the code. I have no idea who wrote it but credit to them. I simply adapted it for this purpose.
Reply
Thanks given by:
#3
Hi and Welcome to the house project!

You are welcome to join us on the projects GitHub repo and open a PR
Reply
Thanks given by:
#4
(12-11-2020, 07:29 PM)12xx12 Wrote: Hi and Welcome to the house project!

You are welcome to join us on the projects GitHub repo and open a PR

house project ?
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)