Hi, I'm coding in GDScript, and I am new to it all, so I've followed along some tutorials by Code with Tom to start making a top down shooter. I followed it along perfectly and it was all going smoothly, until it got to spawning a bullet. Tom said to add in apply_impulse, and I did. However, when I ran the game, it crashed and said that apply_impulse wasn't able to be called back, as it wasn't a known function in the kinematic body 2d. This may be because the video is older, and I'm using the newest version, but some help would be appreciated. Also I will attach the code for anyone interested, although I think I have everything correct. by the way, the apply_impulse thingy is in the func_process(_delta): function.
Code:
extends KinematicBody2D
export var speed = 100
export var bullet_speed = 1000
var bullet = preload("res://player/Bullet2.tscn")
func _process(_delta):
look_at(get_global_mouse_position())
if Input.is_action_just_pressed("fire"):
var bullet_instance = bullet.instance()
bullet_instance.position = get_global_position()
bullet_instance.rotation_degrees = rotation_degrees
bullet_instance.apply_impulse(Vector2(), Vector2(bullet_speed, 0).rotated(rotation))
get_tree().get_root().add_child(bullet_instance)
func _physics_process(_delta):
var direction = Vector2()
if Input.is_action_pressed("move up"):
direction += Vector2(0, -2)
if Input.is_action_pressed("move down"):
direction += Vector2(0, 2)
if Input.is_action_pressed("move left"):
direction += Vector2(-2, 0)
if Input.is_action_pressed("move right"):
direction += Vector2(2, 0)
move_and_slide(direction * speed)