Cant get impulse to work

Godot Version

4.21

Question

Why wont my code work

Error

image

Code


var can_fire = true
var Bullet = preload("res://bullet.tscn")
var bullet_speed = 5000

func _ready():
	pass
	set_as_top_level(true)
	
	
func _physics_process(_delta):
	pass
	position.x = lerp(position.x, get_parent().position.x, 0.5)
	position.y = lerp(position.y, get_parent().position.y + 10, 0.5)
	var mouse_pos = get_global_mouse_position()
	look_at(mouse_pos)
	
func _process(delta):
	var fire
	var Bullet_instance = Bullet.instantiate()
	Bullet_instance.position = get_global_position()
	Bullet_instance.rotation = rotation_degrees
	Bullet_instance.apply_impulse(Vector2(),Vector2(bullet_speed, 0).rotated(rotation))
	get_tree().get_root.call_deferred("add_child", Bullet_instance)
	await get_tree().create_timer(0.4).timeout
	can_fire = true
	if Input.is_action_just_pressed("Fire"):
		fire

Node2D does not have a apply_impulse() function. Search which class has that function and try to fix that.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.