有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在球门碰撞中区分球和球员

嘿,我想做一个基本的曲棍球游戏。 我有关于球场、球员、对手和球的基本物理知识

我正在努力想办法让球进入球门 同时防止球员和对手进入球门

基本上,对手跟随球,球员由用户输入控制。 所以我需要两个限制

我需要创建一个只有球才能通过的形状。。。这可能吗? 如果球越过球门线,也许我可以让对手睡觉

我这样做对吗

Player1只能在红色框中移动 Player2只能在绿色框中移动 球可以在外蓝框中移动

playing field layout


共 (3) 个答案

  1. # 1 楼答案

    为什么不使用简单的碰撞检测

    如果在你的曲棍球场上移动的物体是球员类型,并且他的位置/击球盒与球门相撞,你可以将他的位置改回直线,这样他可能无法与球门相交

    如果对象的类型不是玩家,你可以简单地让对象通过

  2. # 2 楼答案

    如果您使用的是Box2D,可能需要查看传感器

    摘自Box2D Manual

    Sometimes game logic needs to know when two fixtures overlap yet there should be no collision response. This is done by using sensors. A sensor is a fixture that detects collision but does not produce a response.

    You can flag any fixture as being a sensor. Sensors may be static or dynamic. Remember that you may have multiple fixtures per body and you can have any mix of sensors and solid fixtures.

    Sensors do not generate contact points. There are two ways to get the state of a sensor:

    1. b2Contact::IsTouching
    2. b2ContactListener::BeginContact and EndContact
  3. # 3 楼答案

    你不允许球员向左或向右离开球场,是吗?所以你只需要对球员的球门区域做同样的逻辑