【发布时间】:2021-11-04 15:10:32
【问题描述】:
所以我在 Godot 3.3.4 中开发了这款基于 3D 的自上而下的游戏。我为玩家移动编写了一些代码,但它会导致玩家在站在坡道上时缓慢滑动。
我可以想象如何修复它,但我认为我设计了一个非常简单的修复程序,所以我问社区。有没有一种简单的方法可以让玩家在触地时保持原地不动?
(我知道 move_and_slide_with_snap() 方法,但我也无法使其正常工作) (我也知道我忘了应用 delta)
代码如下:
export var speed = 7.5 const GRAVITY = Vector3.DOWN * 100 var velocity = Vector3.ZERO func _physics_process(delta): velocity += GRAVITY * delta velocity = move_and_slide(velocity, Vector3.UP) var input_vector = Vector2.ZERO input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left") input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up") input_vector = input_vector.normalized() velocity.x = input_vector.x * speed velocity.z = input_vector.y * speed move_and_slide(velocity)
这是我的第一个社区问你好,谢谢你。
已解决
我有一些 gif,但显然你需要 10 个代表,而且我是新人所以......
谢谢Theraot,我已经启用了斜坡功能,但有时会起作用。所以我做了一些改变,我认为我可以接受:
extends KinematicBody
export var speed = 750
const GRAVITY = Vector3.DOWN * 10
var velocity = Vector3.ZERO
func _physics_process(delta):
velocity += GRAVITY * delta
velocity = move_and_slide_with_snap(velocity, Vector3.DOWN, Vector3.UP, true, 1, 0.80)
var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
input_vector = input_vector.normalized()
velocity.x = input_vector.x * speed * delta
velocity.z = input_vector.y * speed * delta
move_and_slide_with_snap(velocity, Vector3.DOWN, Vector3.UP, true, 0, 0.785398)
我确信代码几乎可以工作,但动作还不错,它只会在大坡道上滑动一点,所以这可能是一件“有趣”的事情。
我正在关闭它,但如果有人想更正该代码,我可以接受。玩得开心。
【问题讨论】:
标签: game-development godot gdscript