The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

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 "moveandslide" 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:


export (int) var speed = 200

var velocity = Vector2()

func getinput():
velocity = Vector2()
velocity.x += 1
velocity.x -= 1
velocity.y += 1
velocity.y -= 1
velocity = velocity.normalized() * speed

func physicsprocess(delta):
velocity = move

-----Veiw Hierarchy----------------------------------------
|Level 1_ []
|Player_ PlayerSript
|Kenimatic2D node |


Godot version Godot_v3.3.4-stable_win64
in Engine by (12 points)

1 Answer

0 votes

You tried to attach script to scene root instead of adding Player PackedScene as child, and received error #1. Then you "fixed" the error by removing KinematicBody2D inherited functions, including moveandslide() which you use from the script, To add child to the root of scene add Player node with root nodes.add_child().

by (887 points)
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.