【问题标题】:Kinematic object does not detect any collisions - Godot运动学对象未检测到任何碰撞 - Godot
【发布时间】:2018-02-15 12:09:57
【问题描述】:

我正在学习 Godot 游戏引擎,我试图制作一个可以行走但不能穿过其他物体的球,但球会一直穿过其他物体。

代码如下:

extends KinematicBody2D

export var viteza = 140

func _ready():
    set_fixed_process(true)

func _fixed_process(delta):
    delta *= 5
    var motion = Vector2()

    if Input.is_key_pressed(KEY_UP):
        motion[0] = 0
        motion[1] = -1

    if Input.is_key_pressed(KEY_DOWN):
        motion[0] = 0
        motion[1] = 1

    if Input.is_key_pressed(KEY_LEFT):
        motion[0] = -1
        motion[1] = 0

    if Input.is_key_pressed(KEY_RIGHT):
        motion[0] = 1
        motion[1] = 0

    motion = motion * viteza * delta
    set_pos(get_pos() + motion)

场景(图片): Scene

怎么了?

【问题讨论】:

    标签: input collision-detection collision godot gdscript


    【解决方案1】:

    切勿在 KinematicBody2D 中使用 set_pos()。你需要使用 move()。

    【讨论】:

      猜你喜欢
      • 2021-06-28
      • 2022-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-15
      • 1970-01-01
      • 1970-01-01
      • 2017-01-07
      相关资源
      最近更新 更多