0 votes

Hi guys, im new with coding.. i have been wondering why it's not working, my rotator cursor doesn't move and it keep crashing after 2 second. and it always gave me the " invalid set index 'rotation_degrees' (on base: 'null instance') with value of type 'float' "

any feedback will be really appreciate

below is my code

extends KinematicBody2D

const MAXSPEED = 80
const ACCELERATION = 500
const FRICTION = 500

var velocity = Vector2.ZERO

onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get("parameters/playback")

onready var pointer := $Pointer
onready var ray:= $Pointer/RayCast2D

func physicsprocess(delta):

var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
input_vector = input_vector.normalized()#diagonal have same speed with linear speed

if input_vector != Vector2.ZERO:
    animationTree.set("parameters/Idle/blend_position", input_vector)
    animationTree.set("parameters/Walk/blend_position", input_vector)
    animationState.travel("Walk")
    velocity = velocity.move_toward(input_vector * MAXSPEED, ACCELERATION * delta)

elif velocity  != Vector2.ZERO:
    rotate_pointer(velocity)
else:
    animationState.travel("Idle")
    velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
move_and_slide (velocity)

func rotatepointer(pointerdirection: Vector2)-> void:
var temp = rad2deg(atan2(pointerdirection.y, pointerdirection.x))
pointer.rotation_degrees = temp

in Engine by (60 points)

How does your scene-tree look like? Does the KinematicBody2D this script is attached to have a direct child called "Pointer" (case-sensititive!)? This error is basically telling you that you're trying to set a property on a null-object, i.e. the object does not exist.

oh gosh i have to rename Node2D to Pointer for it to work, thank you so much it was really helpfull

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.