parry mechanic in an fps game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Hexadotz

So here’s what im trying to do, I’m trying to implement a parry mechanic to my fps game basically its like a baseball bat, when the player swing the bar at the right moment any projectile coming at them will go back to where the crosshair is at kinda like the parry mechanic in ULTRAKILL if you know it.
Now im not expecting anyone to give me how to exactly do it i just want the logic on how to do it as well as what nodes will help plus what difficulty i might face

:bust_in_silhouette: Reply From: Inces

I think the simplest way would be to code weapon swing in a way it will extend some hitbox collision shape in fixed position in front of your player for a fixed short time, and after that time reset shape scale to 0. Collision with this hitbox will reverse direction of projectile, no if condition needed. Bat swing can be only animation, no need for using bodies or areas for it.

What I mean is :
Baseball bat swing is an animation. It makes your character look like it swings the bat in front of him. Bat will not be real object, will have no body, no collision shape - it will only be mesh and animation.
Your character will have an Area called ParryBox as a child. It will be positioned in some small distance in front of your character. Its collision shape will be a box. Box max extents will reach something like Vector3(10,15,1) - so its Z axis is very thin.
ParryBox masks colliisons only with projectiles
Parrybox code is : on body entered → reverse this body velocity/ or trigger this body parried function.
When no button is pressed ParryBox will remain disabled or its sollision shape shrinked to 0.
Pressing the button will trigger bat swing animation as well as enabling ParryBox/ enlarging it to max extents. After short time ( or on animation ended/ on animation progressed) ParryBox shrinks/disables again.

This will basically create a thin wall for a very short time that will catch projectiles if clicking the button is correctly timed. It will also require good basic state_machine for your character, to not allow him to endlessly click parry or hold it down.

Inces | 2022-02-09 09:28