![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Shortanel |
Hello guys I’m trying to learn movement and I came across an auto-move script from the book I’m learning, but I have a problem:
extends Sprite
export var speed = 100
var action_move_up = InputEventAction.new()
func _ready():
action_move_up.action = "move up"
action_move_up.pressed = true
func auto_move():
Input.parse_input_event(action_move_up)
func _fixed_process(delta):
if Input.is_action_pressed("move_up"):
move(Vector2(0,-1)*delta)
It says that the method move() isn’t declared in the current class. I search the internet and I found people that use move() method without declared it and it works. What I’m doing wrong? I really appreciate an answer…Thank you in advance.
I think the problem is that the script is attached to a sprite node. Sprite nodes don’t have move functions, or at least i don’t think they do. The sprite should probably be parented to a kinematic body 2d, and the script should be attached to that.
Millard | 2020-09-27 16:11
also, I’m not sure if the move() function is still used, because i can’t find it anywhere on the docs. Someone please correct me if I’m wrong.
Millard | 2020-09-27 16:15
The move()
function sounds like KinematicBody2D
code from the 2.1.x version of the engine.
Ertain | 2020-09-27 16:38
What is calling the move_up.action? this is AI, right?
Millard | 2020-09-27 16:54
Is calling an Input Map “move up” that I created and where I put the UP arrow and the “w” key. In theory this code do is that whenever I press the W or up arrow the sprite will go up automatically. I think this visualise a little the code… and sorry for bad english.
Shortanel | 2020-09-27 18:58
The book from I work said that is for the 3.1 build. I think that it shouldn’t be that different from 3.2.
Shortanel | 2020-09-27 19:02