Facepunch / garrysmod-requests

Feature requests for Garry's Mod
84 stars 24 forks source link

Add the ability to include/remove entities from the GM:CalcVehicleView filter #2127

Open MartyX5555 opened 1 year ago

MartyX5555 commented 1 year ago

Description

Sometimes, there are moments where we would like to filter some entity classes globally from colliding with your view while you are seated in 3rd person. Mostly pointing to this line:

As you can see, the only way to modify this, is overriding the entire hook, which is not really ideal for a simple single line change.

Suggestion

The closest approach would be using a global table that contains all the prefixes (used by the EntClass:StartWith(prefix) ) are going to be filtered from the view (looped so ), and since a global table can be modifed from external ways (addons), this can address the issue above. I know performance could be a concern if said table becomes too big, but let me know your point of this.

Limitations

Of course, as you can note it, this change would affect all the seats that make use of this. Its a global change for the calcview, but fits perfectly for cases where that is required (specially when building things and you are using certain custom ents that you wont want to block your view)

Grocel commented 5 months ago

Rubat has pointed me to this in #2302.

This could be a better suggestion for the requested change:

    -- ...
    filter = function( e )
        if e.IgnoreVehicleViewTrace then
            return false
        end

        local c = e:GetClass() -- Avoid contact with entities that can potentially be attached to the vehicle. Ideally, we should check if "e" is constrained to "Vehicle".
        return !c:StartsWith( "prop_physics" ) &&!c:StartsWith( "prop_dynamic" ) && !c:StartsWith( "phys_bone_follower" ) && !c:StartsWith( "prop_ragdoll" ) && !e:IsVehicle() && !c:StartsWith( "gmod_" )
    end,
    -- ...

This will make every entity that has entity.IgnoreVehicleViewTrace being ignored the camera trace. This would work as a static property for SENTs and also work as a dynamic property for every kind of entity. I think it could be more usable for more special cases than using prefixes. The change probably would also support your case. If needed both changes can be done, though.

MartyX5555 commented 3 weeks ago

@Grocel yeah, i like your approach too. It should be just better to individually assign the IgnoreVehicleViewTrace flag to every sent you create instead of my previous suggestion, mainly for performance.

Also, this can fit nicely as var for the SENT parameters, so its more organized for the user.

And yeah, this looks useful for frameworks too, where one entity base inherits the values to new entities, meaning this var can be also inherited (no need to define it again unless otherwise)

Pd: of course, i would say the previous filter struct for the "vanilla" entities should stay, for compatibility.

Grocel commented 3 weeks ago

Yeah my thing was with frameworks in mind. I wish more developers in the GMod space would think like that. Not everyone is an exclusive server developer.