![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | imaginexdevelopment |
I am trying to attatch a player view as a child to a 2d node that holds my level 1 stage. If my player scrip is inheriting from Kenimatic2D I get the following error:
Error #1|: “Script inherits from native type ‘KinematicBody2D’, so it can’t be instanced in object of type: ‘Node2D’”
If I change my exstends constant to “Node2D” as it suggests, I receive this call back error:
Error #2|:“Parser Error: The method “move_and_slide” isn’t declared in the current class.”
This is in reference to a function bellow which lies in the _process loop and is ment to handle movement. The function specified is the only one in documentation refering to it. Currently there is a method in the Vector2 class called “slide()” but It gives the same error as Error#2 but with the function in reference changed to “slide()”
Here is the code from PlayerScrt in the view hierarchy diagram below it:
-------GDscript-----------------------------------------------------
export (int) var speed = 200
var velocity = Vector2()
func get_input():
velocity = Vector2()
if Input.is_action_pressed(“right”):
velocity.x += 1
if Input.is_action_pressed(“left”):
velocity.x -= 1
if Input.is_action_pressed(“down”):
velocity.y += 1
if Input.is_action_pressed(“up”):
velocity.y -= 1
velocity = velocity.normalized() * speed
func _physics_process(delta):
get_input()
velocity = move_and_slide(velocity)