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)

oh- and it's also saying something to do with the move_and_slide() function thingy returning a value, but that value never being used.

There seems to be nothing wrong with your code. If bullet_instance is a RigidBody, it should be fine. As you said before, apply_impulse isn't a function known by a KinematicBody. But remember that you're calling it from the bullet, so that means that bullet is either not a RigidBody, or you didn't define a function called apply_impulse yourself.

As for move_and_slide, the value it returns is the body's new velocity; since the script didn't need it though it's not necessary to store the value. That warning can be ignored.

Thanks for the response, I appreciate it. I have a couple of questions though: 1) What is a RigidBody and how could I make the bullet into one? 2) How could I define the apply_impulse function myself? Thanks for the response again, I am so completely new to Godot and GDScript, and this really helps out :)

Also, should instead have the bullet as a RigidBody or keep it as a KinematicBody? I'm guessing I should change it to a RigidBody.

In Godot, a RigidBody is a kind of physics object like KinematicBody. The difference is that it's movement is almost completely determined by the physics engine; so you'd use it to simulate realistic physics. KinematicBody on the other hand is a physics object whose movement is mostly determined by code, but can still interact well with other physics bodies.

Now, in your case, a RigidBody or a KinematicBody could be used for your bullet. I'd personally go with the KinematicBody since bullets' paths are usually just a straight line in games.

So before I continue, I'd like to know if your bullet already has a script, and if so what its code is.

Thanks for the response- I've just figured it out through a tutorial. I turns out that the person making the tutorial added the bullet as a RidigBody, but I just put it as a KinematicBody. It all works fine now, so thanks!

2 years later