Godot Version
Godot 4.5
Question
My problem stems from inexperience with vector3 math; I want to implement a mechanic wherein the player is able to detect a GRAPPLE POINT in an Area3D, and once it does, the player is flung towards that GRAPPLE POINT, and keep their momentum as they fly through the air past it. This momentum would be linear and would not be like I was hanging from a rope, but instead a single solid TUG.
Idea below:
I have no idea how to do this, however. I managed to implement how the player can press MOUSE1 and detect the GRAPPLE POINT, but actually making the player move towards the point and keep their momentum is just not working, I’m at a loss.
Any help would be appreciated
To get the direction, you can subtract the player’s position from the grapple point’s position. Something like:
velocity = ( to_local(grapple_point.global_position) - position ).normalized() * fling_speed
Or you just use the built-in direction_to() function instead:
velocity = position.direction_to( to_local(grapple_point.global_position) ) * fling_speed
This can be done either once at the beginning or multiple times while moving towards the grapple point, but after the grapple point is reached you want the player to keep the previous velocity.
Unfortunately both of these functions fling me to the right only, it doesn’t go towards the grapple point.
Edit: It actually DOES do the job. I had to remove the “to_local()” function.
Then I would assume the grapple position you used was already in the player’s local coordinates and not the global position?
Well, I guess it doesn’t matter if it is working now.
I’m not too sure, I’m still trying to figure it out, this was a big help however, thanks!
1 Like