1

你好,我是 Godot 的新手(我是法国人,这就是我的英语不完美的原因)

我正在尝试创建一个游戏(自上而下),其原理与相扑战斗相同,将你的对手淘汰出一个圆圈。我遇到的问题是,如果我使用 KinematicBody2D,角色不会相互推动,这是游戏的基础,我看到 RigidBody2D 可以实现,但我在互联网上找不到任何方法来实现它像这样移动:https ://docs.godotengine.org/fr/stable/tutorials/2d/2d_movement.html#rotation-movement 。然后我搜索是否可以将 KinematicBody2D 与另一个 KinematicBody2D 一起推送(以便可以推送),但我也找不到任何方法。

所以我被困在这里,我的问题是这是否可能,特别是我怎么能做到这一点?

感谢阅读,Noflare

4

1 回答 1

0

我相信这里的问题是你没有使用碰撞。该功能move_and_slidemove_and_collide将接合一个运动体移动,并撞击其他体(包括运动体)。

但是,一旦您使用任一功能,您就会意识到它们不会以您在问题中需要的方式相互推动。

来自文档(enfr

  • move_and_collide:移动的物体会移动,如果有碰撞器(任何障碍物),它会在碰撞时立即停止并返回一个KinematicCollision2D物体。
  • move_and_slide:与 相比,采取进一步move_and_collide的行动,移动的物体将滑过对撞机,将其视为墙壁或地板。对平台游戏很有用。

在您的用例中,您别无选择,只能自己控制碰撞。您可以在此处获得有关 KinematicCollision2D 的更多信息:( en , fr )。这可能是你这样做的方式:

var collision = player.move_and_collide(direction_vector)
if (!collision):
  # No collision occurred
  return
else: 
  # Collided with a wall or player
  if (collision.collider == wall) 
    # if you keep track of wall object as a variable to identify it
    # you can have the sumo just stop moving and not process anymore
    return
  else:
    var opponent = collision.collider
    # write game logic to move opponent and yourself
    return

于 2021-07-06T09:09:59.093 回答