Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | knight098 |
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():
pass
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():
velocity.y=0.0
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y -= jumpforce
velocity.y += gravity * delta
velocity.x = move_dir * move_speed
move_and_slide(velocity,Vector2.UP)
point_weapon_at_mouse()
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.