+1 vote

Hey I guys I am trying to create a Canon which will always point and shoot towards my player and the canon is successfully always facing him but when I tried this script :

extends Sprite
var player=null

var rot_sped=0.1
var fire_rate=0.5
var fire_time=0.0

var canonbullet=preload("res://CanonBullet.tscn")

func _physics_process(delta):
    if player==null:
    var dir_to_player=player.global_position-global_position
    if fire_time>fire_rate:

func fire():
    var canonbullet_inst=canonbullet.instance()
    var dir_to_player=(player.global_position-global_position).normalized()

func set_player(p):

I'm getting Invalid set index 'move_dir' (on base: 'KinematicBody2D') with value of type 'Vector2' on


This here is my CanonBullet Script :

extends KinematicBody2D

var move_dir=Vector2()
var move_speed=80

func _physics_process(delta):
    var coll=move_and_collide(move_dir*move_speed*delta)
    if coll:
        if coll.collider.name=="Player":
            print("You Died")
in Projects by (403 points)
edited by

I fixed it ! My CanonBullet Script wasn't attached :P

So urm... how did you attach it? Same problem here.

I just realized that even though I had this script, it wasn't attached to Cannon Bullet. So I simply just went tot he Cannon Bullet scene. After that I just selected the top node in that scene, did the same step that'll you do to add a script but instead you will have an option of selecting the script you want to add and that was it !

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.