![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | mbnoimi |
Hi,
Sorry for silly question (this is my first 4 hrs with Godot).
I’m unable to access set_pos method from Node2D object
Error message:
Invalid call. Nonexistent function ‘set_pos’ in base ‘CanvasLayer’.
Snippet
extends KinematicBody2D
var motion = Vector2(0, 0)
const SPEED = 1000
const GRAVITY = 300
const UP = Vector2(0, -1)
const JUMP_SPEED = 4000
const WORLD_LIMIT = 8000
signal animate
func _ready():
pass
func _physics_process(delta):
apply_gravity()
jump()
move()
animate()
move_and_slide(motion, UP)
touch_controls()
func touch_controls():
# get_node("Camera2D/LeftCanvas").position = $Camera2D.get_camera_position()
# $Camera2D.get_camera_position()
var viewport = get_node("/root").get_children()[0].get_viewport_rect().size
var viewport_res = get_node("/root").get_children()[0].get_viewport_rect().size
var viewport_scale = 600/viewport.y
$Camera2D/LeftCanvas/LeftControls.set_pos(Vector2(0, 500))
print(viewport_res)
func animate():
emit_signal("animate", motion)
func apply_gravity():
if position.y > WORLD_LIMIT:
end_game()
if is_on_floor():
motion.y = 0
elif is_on_ceiling():
motion.y = 2
else:
motion.y += GRAVITY
func end_game():
get_tree().change_scene("res://Scenes/GameOver.tscn")
func jump():
if Input.is_action_pressed("Jump") and is_on_floor():
motion.y -= JUMP_SPEED
func move():
if Input.is_action_pressed("Right") and not Input.is_action_pressed("Left"):
motion.x = SPEED
elif Input.is_action_pressed("Left") and not Input.is_action_pressed("Right"):
motion.x = -SPEED
else:
motion.x = 0