move_and_slide() 调用的参数太多

问题描述 投票:0回答:1
extends CharacterBody2D

var speed = 150
var jumpforce = 500
var gravity = 700

var vel = Vector2()

func _physics_process(delta):
    if Input.is_action_pressed("player_left"):
        vel.x -= speed
    elif Input.is_action_pressed("player_right"):
        vel.x += speed
    
    move_and_slide(vel, Vector2.UP)

为什么会出错???错误:move_and_slide() 调用的参数太多。预计最多 0 个,但收到 2 个。

我看了如何在 godot 上制作游戏的指南,但是在指南 3 版本的引擎上,我坐在 4 上,因为我几乎不知道引擎和 gdscript 的基础知识,我发现很难自己解决这个问题,你可以吗帮忙吗?

gd godot gdscript
1个回答
0
投票

在版本 4 中,velocity 现在是一个节点属性,还有 up_direction 等。 并且

move_and_slide()
现在不接受任何参数。在您的代码中,替换此:

move_and_slide(vel, Vector2.UP)

有了这个:

move_and_slide()

同时删除您的

vel
变量并更新如下:

velocity.x += speed

它应该有效。

© www.soinside.com 2019 - 2024. All rights reserved.