【问题标题】:In Godot, how to limit vector.x, if vector.y has reached maximum?在 Godot 中,如果 vector.y 已达到最大值,如何限制 vector.x?
【发布时间】:2020-08-01 07:42:00
【问题描述】:

我是 godot 引擎的新手。我正在尝试制作一款太空射击游戏,但遇到了一个小问题。 我正在使用该代码移动我的船:

if button_up.is_pressed():`
    velocity += Vector2(acceleration, 0).rotated(rotation + deg2rad(-90))
move_and_slide(velocity)

我做到了,所以船会移动到它指向的地方,它工作得很好。但是,当我移动到 1 和 89、91 和 179 等之间的度数时,velocity.x 和 velocity.y 都会继续上升,直到达到 max_speed,这导致我的船直接移动 45、135、225 或 315 度和不是它指向的地方。 我想这样做,例如当velocity.x 达到max_speed 时,velocity.y 被限制为它的当前值。有可能吗?

提前谢谢你,对不起我的英语

【问题讨论】:

    标签: 2d godot


    【解决方案1】:

    在 move_and_slide 之前,做velocity = velocity.clamped(max_speed)

    如果小于最大值,这不会有任何影响,但如果超过,则会将其设置为最大值。

    【讨论】:

      猜你喜欢
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多