0 votes

I am trying to get object rotating with my mouse position.
extends KinematicBody2D

onready var weapon_base = $Weaponbase
export var move_speed = 100.0
export var gravity = 400
var velocity = Vector2()
export var jumpforce = 200.0

func _ready():

func _physics_process(delta):
    var move_dir = 0
    if Input.is_action_pressed("move_left"):
        move_dir -= 1
    if Input.is_action_pressed("move_right"):
        move_dir += 1

    if is_on_floor():

    if Input.is_action_just_pressed("jump") and is_on_floor():
        velocity.y -= jumpforce

    velocity.y += gravity * delta
    velocity.x = move_dir * move_speed


func point_weapon_at_mouse():
    var vec_mouse = get_global_mouse_position() - weapon_base.gobal_position
    weapon_base.global_rotation = atan2(vec_mouse.x, vec_mouse.y)

It is giving out an error

Invalid get index 'gobal_position' (on base: 'Node2D').
re read the code but cant find the flaw.

Godot version 3.3.2
in Engine by (15 points)

1 Answer

+1 vote
Best answer

You've written gobal_position instead of global_position, on first line of point_weapon_at_mouse().

by (21,714 points)
selected by
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 Frequently asked questions and 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 [email protected] with your username.