Godot Version
Godot Engine v.4.6.1
Question
Hello everyone! I am new to programming and wanted to make a small game about a robot platforming his way through the main planets of the solar system. I wanted to have a dash like mechanic but making it a grappling hook that only shoots in the front of the character. I’m following a tutorial for how to get the grappling hook to actually shoot but, in the example the man is having the grappling hook follow the mouse cursor when, I would just like it to shoot in front of the character in the direction they’re facing. Right now, this is the code for the grapple itself:
func interpolate(length, duration = 0.2):
var tween_offset = get_tree().create_tween()
var tween_rect_h = get_tree().create_tween()
tween_offset.tween_property(self, "offset",Vector2(0,length/2.0), duration)
tween_rect_h.tween_property(self, "region_rect",Rect2(0,0,16,length), duration)
func _input(event):
if event.is_action_pressed("Hook"):
interpolate(150, 0.2)
await get_tree().create_timer(0.2).timeout
reverse_interpolate()
func reverse_interpolate():
interpolate(0,0.75)
Here’s what he puts in the video for it to follow his mouse cursor:
func _input(event):
if event.is_action_pressed("Hook"):
look_at(get_global_mouse_position())
Let me know if you need anymore information! Also, please get as technical as possible with the explanation, I’m trying to learn as much as I can. As a little bonus round, I would also like a little buffer in momentum whenever the hook is shot all the way to when it lands. If someone could help with that too that’d be swell! Thank you!