How to make a rigid body 2d shoot with velocity

Hi, I’m looking for advice on how I make the ball in my peggle clone to shoot with linear velocity through gdscript to make it More like a cannon effect. here is the code for the rigid body:

extends RigidBody2D
	
func _ready() -> void:
	freeze = true

func _input(_event: InputEvent) -> void:
	if Input.is_action_pressed("Aim"):
		pass

And there is also a cannon so here is its code:

extends Marker2D
	
func _input(_delta):
	look_at(get_global_mouse_position())
	if Input.is_action_just_released("Aim"):
		$RigidBody2D.freeze = false

Right now it is just dropping the rigid body when i’d like it to be launching it.

Use RigidBody2D::apply_central_impulse()

1 Like