gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 06:15:05 25 4
gpt4 key购买 nike

嘿,我正在尝试制作一款基本的曲棍球风格游戏。我掌握了与球场、球员、对手和球相关的基本物理知识。

我正在努力弄清楚如何让球进入球门同时防止球员和对手进入球门。

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

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

我的做法是否正确?

玩家1只能在红框内移动Player2 只能在绿框内移动球可以在外面的蓝色盒子里四处移动

playing field layout

最佳答案

如果您使用的是 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

关于java - 在球门碰撞中区分球和球员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5404898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com