KinematicBody2D仅向左和向右移动

时间:2020-04-03 13:18:54

标签: 2d godot

所以我是编码的新手,所以我遵循了本教程: https://www.youtube.com/watch?v=BeSJgUTLmk0

而且我不能上下移动KinematicBody2D

这是代码

extends KinematicBody2D


var MaxSpeed = 500 
var Accel = 5000
var Motion = Vector2.ZERO


func _physics_process(delta):
    var Axis = GetInputAxis()
    if Axis == Vector2.ZERO:
        ApplyFriction(Accel * delta)
    else:
        ApplyMovement(Axis * Accel * delta)
    Motion = move_and_slide(Motion)

func GetInputAxis():
    var Axis = Vector2.ZERO
    Axis.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
    Axis.y - Input.get_action_strength("ui_up") - Input.get_action_strength("ui_down")
    return Axis.normalized()

func ApplyFriction(amount):
    if Motion.length() > amount:
        Motion -= Motion.normalized() * amount
    else:
        Motion = Vector2.ZERO

func ApplyMovement(acceleration):
    Motion += acceleration
    Motion = Motion.clamped(MaxSpeed)

是的,我的键绑定设置正确

0 个答案:

没有答案
相关问题