I've been trying to modify the grappling hook from ZMovement to be more physics-based. I managed to adapt some code from some Unity tutorials, and it mostly works, but it still feels really off. The main issue is that it starts bouncing you up and down while you're swinging instead of swinging in a clean arc. I think it does this because of the different way GZDoom handles gravity compared to Unity, but I can't figure out how to fix it. Any ideas?
UPDATE: Improved grappling hook code by GrayFace. It seems to work perfectly now. Anyone can use or modify it however they want.
UPDATE 2: Added mid-air movement control while swinging, and fixed a bug with the rope not appearing until the hook hits something.
UPDATE 3: Pressing use or jump now detaches the hook. Pressing Fire or AltFire with a hook attached will retract and extend the rope, respectively. AltFire with no hook attached launches a hook that reels the player in.
Help with physics-based grappling hook
Moderator: GZDoom Developers
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
-
- Posts: 19
- Joined: Sat Dec 23, 2023 4:04 am
- Preferred Pronouns: No Preference
- Operating System Version (Optional): Windows 7
Help with physics-based grappling hook
- Attachments
-
GrapplingHook.pk3
- (7.29 KiB) Downloaded 9 times
Last edited by Ershantik on Sat May 24, 2025 7:54 pm, edited 6 times in total.
-
- Posts: 40
- Joined: Mon Feb 13, 2023 1:34 am
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Windows 7 x64
- Graphics Processor: ATI/AMD with Vulkan/Metal Support
Re: Help with physics-based grappling hook
"ropeAngle = acos(down dot hookToPlayer)" must be "ropeAngle = acos((down dot hookToPlayer)/hookDist)". It also shouldn't exist, because the only use of it is "cos(ropeAngle)".
-
- Posts: 40
- Joined: Mon Feb 13, 2023 1:34 am
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Windows 7 x64
- Graphics Processor: ATI/AMD with Vulkan/Metal Support
Re: Help with physics-based grappling hook
Here you go, this was fun tinkering. Credit me by my nickname.
- Attachments
-
GrapplingHook.zip
- (5.58 KiB) Downloaded 21 times
-
- Posts: 19
- Joined: Sat Dec 23, 2023 4:04 am
- Preferred Pronouns: No Preference
- Operating System Version (Optional): Windows 7
Re: Help with physics-based grappling hook
I updated the download before you posted that, but your version seems to work perfectly, and it's so much simpler than what I was trying. Thank you. Could you explain a bit about how it works this way?
-
- Posts: 40
- Joined: Mon Feb 13, 2023 1:34 am
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Windows 7 x64
- Graphics Processor: ATI/AMD with Vulkan/Metal Support
Re: Help with physics-based grappling hook
Looks like it's best to set ForcePower to 1 actually.
Adding "plr.vel/2" to player position in "hookToPlayer" calculation in HookPhysics makes a big difference getting rid of wobble. Note that "restLength" is divided by Elasticity when assigned. I than choose ForceFactor based on gravity for it to hold player on the same level when shot straight up at the ceiling. Otherwise it's just the rope itself, the more it's stretched in % of resting length, the bigger the force.
[edit] I also just noticed that "if(!hooked) return;" should be moved to be the first line of HookPhysics - not a bug, it's just better this way.
[edit2] Make sure you've downloaded the last version I've posted. I posted and deleted 2 versions before it.
[edit3] ForcePower slightly above 1 is nice, like 1.2.
Adding "plr.vel/2" to player position in "hookToPlayer" calculation in HookPhysics makes a big difference getting rid of wobble. Note that "restLength" is divided by Elasticity when assigned. I than choose ForceFactor based on gravity for it to hold player on the same level when shot straight up at the ceiling. Otherwise it's just the rope itself, the more it's stretched in % of resting length, the bigger the force.
[edit] I also just noticed that "if(!hooked) return;" should be moved to be the first line of HookPhysics - not a bug, it's just better this way.
[edit2] Make sure you've downloaded the last version I've posted. I posted and deleted 2 versions before it.
[edit3] ForcePower slightly above 1 is nice, like 1.2.
-
- Posts: 19
- Joined: Sat Dec 23, 2023 4:04 am
- Preferred Pronouns: No Preference
- Operating System Version (Optional): Windows 7
Re: Help with physics-based grappling hook
I can't thank you enough. This is amazing. It'll probably be a long time before I release anything that uses this, but at least now, it's here for anyone to use. Thanks again.
Re: Help with physics-based grappling hook
How do I plug this into my map to test. I added the pk3 as a resource in map options in UDB, but I'm not seeing a custom Thing weapon to place that reflects the weapon