Godot萌新   喵Ta  
 Godot?YYDS!
我本来想做一个角色移动,代码:
extends Area2D

@export var speed = 300
var screen_size

func _ready():
screen_size = get_viewport_rect().size

func _process(delta):
var velocity = Vector2.ZERO # The player's movement vector.
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
if velocity.length() > 0:
velocity = velocity.normalized() * speed
$AnimatedSprite2D.play()
else:
$AnimatedSprite2D.stop()
position += velocity * delta
position = position.clamp(Vector2.ZERO, screen_size)
但是不知道为啥,它总是不能很好的移动,每次都是上下左右会在某一个地方卡住,按键过不去
   
[投稿须知]
投稿邮箱:hareqj@163.com
教程投稿:可提供B站视频BV号,会直接生成视频播放页。
游戏投稿:须原创,请提供 作品web版文件、作者、简要操控说明。
内容举报邮箱:hareqj@163.com,请告知内容编号(右上角)及违规说明。
Copyright Godot社区 Godot2D.com All Rights Reserved.
京ICP备13032831号