does apply.impulse code not work in area2D type?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By chihiro Jk

I’m new to Godot and I’m trying to code fire bullets, when I use area2d type, there’s an error in the ‘apply impulse’ section like "invalid call. Nonexistent function ‘apply_impulse’ in base ‘Area2D(’. What do I have to do?
here’s my code :

extends Area2D

export (PackedScene) var bullet

func _on_KillTimer_timeout():
	pass # Replace with function body.

func _on_Bullet_body_entered(body):
	if !body.is_in_group("player"):

then my code in :

extends Sprite

    export var bullet_speed = 1000
    export var fire_rate = 0.2
    var bullet = preload("res://Characters/Player/Bullet.tscn")
    var can_fire = true
    func _process(delta):
    	var mouse_direction: Vector2 = (get_global_mouse_position() - global_position).normalized()
    	if Input.is_action_pressed("fire") and can_fire:
    		var bullet_instance = bullet.instance()
    		bullet_instance.position = $BulletPoint.get_global_position()
    		get_parent().screen_shaker._shake(0.2, 2)
    		bullet_instance.rotation_degrees = rotation_degrees + rand_range(0.1, 0.1)
    		bullet_instance.apply_impulse(Vector2(), Vector2(bullet_speed, 0).rotated(rotation))
    		can_fire = false
    		can_fire = true
:bust_in_silhouette: Reply From: kidscancode

apply_impulse() is a method that belongs to the RigidBody2D class: RigidBody2D — Godot Engine (stable) documentation in English

So no, you can’t use it with an Area2D. It seems that you have copied code that someone wrote to implement a RigidBody2D bullet, but you’re trying to run it on the wrong type of node.

There’s nothing wrong with using an Area2D for a bullet - indeed, it’s probably the most common node used for this. But areas aren’t moved/controlled by the physics engine, so you have to change their position in code rather than applying forces or impulses like you’d do with a rigid body.