Skip to content

Raycast look-ahead for projectiles and Bounding Box-based weapon collision + fixes and optimizations.#2781

Merged
KABoissonneault merged 8 commits into
Interkarma:masterfrom
RedRoryOTheGlen:RaycastProjectiles
Jun 9, 2026
Merged

Raycast look-ahead for projectiles and Bounding Box-based weapon collision + fixes and optimizations.#2781
KABoissonneault merged 8 commits into
Interkarma:masterfrom
RedRoryOTheGlen:RaycastProjectiles

Conversation

@RedRoryOTheGlen

@RedRoryOTheGlen RedRoryOTheGlen commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Implemented raycast-based collision for DaggerfallMissile from PR #2472 by numidium . Revised the layer mask switching and fixed the now-off-center arrow model resulting from the change. Also applies the layer mask to the Touch spell detection and tweaks the GetAimPosition method to prevent the player from targeting themselves with their own Touch spells addressing Issue #2768.

Additionally, incorporated the optimizations to DaggerfallMissile from PR #2770 by DanyilYedelkin, taking into account the new raycast-based collision when needed. Original PR had an issue which applied the Player-excluding layer mask to all projectiles and area-of-effect regardless of caster which has been corrected. Also included the changes to WeaponManager that fixes the player melee attacks being blocked by colliders on the IgnoreRaycast layer (Issue #2767), as well as an optimization.

UPDATE:
Implemented the bounding box-based weapon collision for players. At the default settings, this does the following things when the player performs a melee attack:

  1. Uses Physics.OverlapBox() to grab all colliders (using the WeaponManager layermask) in front of the player in an area based on the default weapon reach + spherecast radius.
  2. For each collider, check if it is an entity
  3. Check if collider's center is inside the camera's field-of-view
  4. Check if line-of-sight to collider's center is unobstructed by environment and other entities (as well as within the weapon reach value)
  5. Add collider to list (hitColliders)
  6. After all overlapped colliders have been finished, perform WeaponDamage() on all colliders in hitColliders list
  7. If hitColliders is empty, perform the old spherecast check to handle bashing doors and other actionable objects.

Two settings are included: Hit Detection and Protect Friendlies and Neutrals.

By default, Hit Detection is set to Performance and behaves as described above. If Hit Detection is set to Quality, then there are additional checks that happen in Steps 3 and 4 if their initial checks fail. There can be up to 4 tests checking if some other part of the target is in view or has clear LOS. If a test succeeds, the following tests are skipped. This lets the player hit entities that may be partially covered by the environment or other entities.

Protect Friendlies and Neutrals is enabled by default. While enabled, the check in Step 1 will skip wandering commoners and entities that are pacified, and these targets can only be damaged/killed by the old spherecast check in Step 7. This prevents attacking them by accident if the player is fighting an enemy while they're around.

Both settings can be accessed in the DFU Advanced Settings menu under Gameplay. They can also be changed mid-game from the Advanced Controls window.

For illustration:
image
image

The green capsule is the default DFU attack spherecast. The red box is the OverlapBox check. After the field-of-view, line-of-sight and weapon reach checks, the player's attack area is reduced to the semi-spherical shape inside the blue lines. In effect, it is somewhat like sweeping the spherecast across the whole of the player's view.

If the player increases the camera FOV through the settings, this will also increase the attack area but not the total weapon reach, for consistency:
image

…yer mask to Touch spell target detection as in PR Interkarma#2770. Removed the aimPosition offset to prevent the player's pre-cast check detecting their own collider as a target.
… with the origin of collision checks. Moved the isArrow offset code into GetAimPosition method so the arrow still spawns in the same place it did before.
…Interkarma#2770 as well as the WeaponManager layer mask fix. Removed the explicit exclusion of IgnoreRaycast layer from the layer mask initialization because DefaultRaycastLayer apparently already excludes it.
…l caster to use the Player-excluding layer mask. Now the Player-excluding layer mask is only assigned if the caster is the Player.
numidium
numidium previously approved these changes Apr 4, 2026
@KABoissonneault

Copy link
Copy Markdown
Collaborator

Did you get to try it out numidium, or is that from reading the code? I do like that this PR replaces two others, I could probably knock down both, but it would probably help to have people - other than the author - test it

…lasses to use the appropriate layer mask (and initialize it if it isn't). Applied this new method to the player Touch targeting check in EntityEffectsManager.CastReadySpell to completely prevent self-targeting with Touch spells.
@RedRoryOTheGlen

Copy link
Copy Markdown
Contributor Author

I have been focusing on the Touch usage a bit more and last commit is supposed to fix the self-targeting issues still happening while moving and sprinting due to enabling Headbob and the player's SmoothFollower lagging behind the player collider.
Would definitely appreciate more people trying it out to see if things can be handled better.

@RedRoryOTheGlen

RedRoryOTheGlen commented Apr 6, 2026

Copy link
Copy Markdown
Contributor Author

Additionally, since this already changes WeaponManager, I would like to try implementing bounding box based player melee attacks with multi-hit in this PR as well, if that would be acceptable?
If not, I can make a new PR for it later, but I would definitely use this PR as a base.

Test footage of bounding box-based weapon collision Even with lots of playtime on DF, I still don't really know how Daggerfall did it, but I attempted to achieve the same feel with just an OverlapBox and Raycasts for a quick LOS check. Then I added some (optional) enhancements like friendly fire protection, radial reach and a complex-LOS check as QOL.

…vanced Settings menu under Gameplay tab and to in-game Advanced Controls window.
@RedRoryOTheGlen RedRoryOTheGlen changed the title Raycast look-ahead for projectiles and weapon collision fixes and optimizations. Raycast look-ahead for projectiles and Bounding Box-based weapon collision + fixes and optimizations. Apr 7, 2026
…LOS check block to avoid having the same series of checks written twice.
@RedRoryOTheGlen

RedRoryOTheGlen commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

After further testing on 1.2-Test3, I've implemented TOB-style radial reach check to prevent the player from attacking beyond the default DFU weapon reach value.

Updated the OP with some more info including the effect of the new check.

Vwing added a commit to Vwing/daggerfall-unity-android that referenced this pull request Jun 8, 2026
Interkarma#2781 already ignores the Automap layer in DaggerfallMissile and WeaponManager

@Daneel53 Daneel53 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR was deeply tested into 1.2 Test3 in the same time as Vwing's PR 2790.
Both authors confirm that all is now working as intended.
Both PR are ready to be integrated into the game.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants