找回密码
 立即注册

QQ登录

只需一步,快速开始

Godot角色8向移动

已有 453 次阅读2024-11-22 17:10 |个人分类:Godot|系统分类:日常记录

 在这种情况下,玩家使用四个方向键移动(包括对角线)
extends CharacterBody2D

var speed = 400  # speed in pixels/sec

func _physics_process(delta):
    var direction = Input.get_vector("left", "right", "up", "down")
    velocity = direction * speed

    move_and_slide()
方案 2:旋转和移动
在这种情况下,左/右操作可以旋转角色,而上/下操作则可以让角色朝任何方向前进或后退。这有时被称为 "小行星式 "移动。
extends CharacterBody2D

var speed = 400  # move speed in pixels/sec
var rotation_speed = 1.5  # turning speed in radians/sec

func _physics_process(delta):
    var move_input = Input.get_axis("down", "up")
    var rotation_direction = Input.get_axis("left", "right")
    velocity = transform.x * move_input * speed
    rotation += rotation_direction * rotation_speed * delta
    move_and_slide()

路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

关闭

站长推荐上一条 /2 下一条

QQ|Archiver|手机版|小黑屋|去背|站长工具|翼龙汇 |网站地图

GMT+8, 2025-5-17 23:10 , Processed in 0.053896 second(s), 20 queries .

Powered by Elonghui!

!copyright2024!

返回顶部