I want to be able to click on the screen and spawn an explosion that blasts objects and the player away from the point of explosion. So it would be similar to rocket jumping except you click where the explosion happens. It would be side-view and their would be gravity if that changes anything.
I’ve looked at tutorials but none of them seem to work. Can you guys help? By the way I’ve only been using godot for 2 months so I’m pretty new.
extends Node2D
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("click"):
for node: Node in get_parent().get_children():
if node is RigidBody2D:
var mouse_position: Vector2 = get_viewport().get_camera_2d().get_global_mouse_position()
var direction: Vector2 = node.global_position - mouse_position
var distance: float = direction.length()
var impulse_power: float = 500.0
var range: float = 500.0
if distance < range:
node.apply_impulse(direction.normalized() * impulse_power)
I have additionally created an InputAction “click” in the Project Settings.