Skip to content

Turret Targeting Ability #1

@austinjdean

Description

@austinjdean

Hello,

I want to preface this by saying this mod has revolutionized my gunboat that I made with ValheimRAFT mod. Previously I was using Draugr Archers and Growths trapped in cages as turrets, but this works so much better. I also love your YouTube channel where you walk through the code. Thank you for your work!!!!

Here is the nature of the bug I'm seeing:

Once the turrets acquire a target, they are VERY effective. However, I find that in some cases, the turrets will not realize there's a target right in front of them - well within range, and clearly visible.

Sometimes I can correct this behavior by turning / elevating the boat slightly, after which there's a chance the turrets will see the target and fire - but it's a tenuous workaround at best.

To be clear, the turrets have no issue annihilating a horde of 50 trolls that I spawn with devcommands. It's only SOME of the naturally spawned creatures that they will fail to detect. Other naturally spawned creatures are detected and shot, no problem. I have not yet identified the pattern.

I have a couple hunches on where this bug may be coming from; the first is within the FindTarget() function located here: https://github.com/MeatwareMonster/MoreDefenses/blob/master/MoreDefenses/Scripts/Turret.cs#L205

Perhaps some of the conditions in line 210 and below occasionally do not evaluate properly and thus lead to false negative? I couldn't find the definition for CanSeeCharacter() but maybe it's returning an incorrect value sometimes? It could also be the if (IsContinuous) condition on line 219.

It may also be related to where FindTarget() is called from - line 155 within the Update() function: https://github.com/MeatwareMonster/MoreDefenses/blob/master/MoreDefenses/Scripts/Turret.cs#L155

Any of the conditions leading up to StartCoroutine(FindTarget()); may be causing Update() to return prematurely, e.g. if (m_nview == null || !m_nview.IsOwner()) on line 145, or perhaps m_target is null when it shouldn't be, or it may have to do with the value for m_updateTargetTimer or how it gets updated. It could even be whatever calls the Update() function, but I found no references to it, so that bit may be out of our control. Perhaps called by the game or something.

But again these are only hunches. I have no experience with developing mods or working with C#. I have worked with code and scripts in general though.

For what it's worth, in my situation, this applies only to Ballista turrets. I also modified my config a bit, turning them into machine guns. I'm going for something to this effect: https://www.youtube.com/watch?v=Sax5tURLTrw

I love this mod but it's frustrating to have my ship parked right next to a fuling and watch him wander around, untouched! He should be getting promptly cut down!

{
    "name": "Ballista",
    "bundleName": "turrets",
    "prefabPath": "Assets/_Project/Prefabs/MMBallista.prefab",
    "description": "Possessed, but seems to have good intentions.",
    "pieceTable": "Hammer",
    "enabled": true,
    "type": "Projectile",
    "fireInterval": 0.00001,
    "damage": 4,
    "frostDamage": 4,
    "fireDamage": 4,
    "poisonDamage": 4,
    "spiritDamage": 4,
    "range": 100,
    "canShootFlying": true,
    "resources": [
      {
        "item": "Bronze",
        "amount": 20
      },
      {
        "item": "FineWood",
        "amount": 20
      }
    ]
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions