区分球门碰撞中的球和球员

发布于 2024-10-25 13:00:24 字数 337 浏览 3 评论 0原文

嘿,我正在尝试制作一个基本的曲棍球风格的游戏。 我了解球场、球员、对手和球的基本物理原理。

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

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

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

我以正确的方式处理这件事吗?

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

比赛场地布局

Hey, I'm trying to make a basic hockey style game.
I have the basic physics working with the pitch, a player, an opponent, and a ball.

I'm struggling to figure out how I can allow the ball to travel into the goal
while keeping the player and opponent from going into the goal.

Basically the opponent follows the ball, and the player is controlled by user input.
so there are two restrictions I need.

I need to create a shape that only the ball can go through... is this even possible?
Maybe I can sleep the opponent if the ball passes the goal line?

Am I going about it the right way?

Player1 can only move around in the red box
Player2 can only move around in the green box
The ball can move around in the outer blue box

playing field layout

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

酒绊 2024-11-01 13:00:24

如果您使用 Box2D,您可能想研究一下传感器

摘自 Box2D 手册

有时游戏逻辑需要知道两个灯具何时重叠但不应该有碰撞响应。这是通过使用传感器来完成的。传感器是一种检测碰撞但不产生响应的固定装置。

您可以将任何装置标记为传感器。传感器可以是静态的或动态的。请记住,每个主体可能有多个固定装置,并且可以任意组合传感器和固体固定装置。

传感器不生成接触点。有两种方法可以获取传感器的状态:

  1. b2Contact::IsTouching
  2. b2ContactListener::BeginContact 和 EndContact

If you're using Box2D, you probably want to look into Sensors.

Taken from the 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
孤独患者 2024-11-01 13:00:24

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

如果在曲棍球场上移动的对象是球员类型,并且他的位置/击球区与球门碰撞,则您将他的位置更改回线,因此他可能无法与球门相交。

如果对象的类型不是玩家,您只需让对象通过

why don't you use simple collision detection?

if the object that moves over your hockey field is of type player and his position/hitbox collides with the goal, you change his position back to the line, so he possibly can't intersect with the goal.

if the type of object is not a player you simple let the object pass

酒儿 2024-11-01 13:00:24

好吧,你不允许玩家向左或向右离开比赛场地,是吗?所以你只需要对球员的球门区域执行相同的逻辑即可。

Well, you don't allow the player to leave the playing field to the left or right do you? So You just need to do that same logic for the goal area for players.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文