#Grappling hook not working as intended

1 messages · Page 1 of 1 (latest)

simple horizon
#

Hi! I've been trying to make a grappling hook for my game, but whenever i attach myself to the hook, the node that connects to the player seems to teleport to some random point along the radius of where the hook can reach. This only happens after i detach myself from the hook for the first time after loading the game in debug. I have no clue why this happens.

The hook is made of a static grapple_anchor node and a moving player_anchor node that are connected via a pinjoint node. In the code for the player and the grappling hook, I've written it so that the player will reparent itself to the player_anchor and disable it's usual movement so the player moves with the player anchor. If the player releases the grapple button, the player will reparent itself to its original parent. I used a bit of math to make sure the player_anchor always leans towards the player when not attached as well.

In the video, you can see that the first time I attach to the hook, the player appears next to the grapple_anchor for a split second before appearing where it should be. After I detach and reattach myself later, though, you can see the player seems to appear way higher than where it should be, and proceeds to spin around really fast, seemingly due to some built up momentum somehow.

cobalt shore
#

Try printing out your player_anchor's linear_velocity and angular_velocity

#

if you are intent on keeping it as a rigidbody there is a good chance you'll need to go digging into _integrate_forces

#

though for an application like this I would frankly recommend just hand-rolling the physics yourself and making player_anchor a node3d or characterbody3d

#

unless you want to make a game that's got a kinda floppy feel, ala gangbeasts or some such

#

when you set the transform of a rigidbody, it doesn't reset linear_velocity or angular_velocity, and it's not really clearly defined how the physics engine conserves/preserves/modifies those while transform is being manipulated externally

#

and you can't set linear_velocity or angular_velocity in _physics_process because it may cause inconsistent behavior if the physics engine ticks after your node does

#

i suspect if you stick with the rigidbody approach you'll want to have an is_active boolean if you don't already (sorry I skimmed your code), and in _integrate_forces you'll want to set linear_velocity and angular_velocity to Vector3.ZERO every frame that is_active = false

#

you'll also probably want to reset them to zero just to be safe once the grapple is initiated

#

or rather set them to the incoming linear_velocity of the player