Closed cmr624 closed 7 months ago
Ah, I didn't describe the issue I mentioned in the title, which is that repeatedly firing a wieldable causes framerate dips
Get_Camera_Collusion() gets a world space collision point of whatever the camera is pointed at, depending on the equipped wieldable range.
You are correct that technically it shouldn't be called for every wieldable per default, so I'll look into moving this out of the attempt_action_primary()
function.
It's mostly needed for projectile weapons as it is used to calculate which direction the projectiles need to be fired at in a way that lines up with the player crosshair, while also respecting any potential collisions.
How many times are you calling this? If you're creating a very high fire-rate weapon, making it hitscan based is porbably more performant.
understood, thank you for the explanation!
in my case, its just a watering can with a simple action, and was trying to change to a press and hold.
I noticed the framerate drops when I was spamming the primary action button, I can also look into if how the ammo is set up (I tried to basically disable it) causes issues where it is allowed to fire too many times
Working on this in this repo! wieldable.gd
Ah okay! Give me a second and I can probably update this to make your life easier.
Okay, please take a look at https://github.com/Phazorknight/Cogito/commit/a0656b0cdfd9223d8ae85a39c6d7715b00b8f51d
The Get_Camera_Collision
call has been moved inside the Toy Pistol, so now it's not being called by default by every wieldable in the primary action.
primary action now passes a is_released parameter, which works the same as the one for the secondary action. This should enable you to easier set up wieldables that have "hold down the button" type actions.
I haven't really taken a look at your script but if you're trying to make a watering can that dispense water while the primary action button is held, I'd probably try to just copy the flashlight script, use the "charge" as the water level and adapt it that it turns on when primary action is pressed and then turns off when primary action is released.
Thank you! This really helps!
and thanks for the direction on the watering can - I'll definitely look into hooking into that!
We can close this since it's not a framerate issue!
Am wondering what the code in Get_Camera_Collision in PlayterInteractionComponent does, and why it's called on every wieldable primary action fire? when overriding the function in my class, it would be great to optionally decide not to call this function if it's not serving the function of the custom wieldable?
COGITO/Components/PlayerInteractionComponent.gd#L242
thank you!