区分球门碰撞中的球和球员
嘿,我正在尝试制作一个基本的曲棍球风格的游戏。 我了解球场、球员、对手和球的基本物理原理。
我正在努力弄清楚如何让球进入球门 同时防止球员和对手进入球门。
基本上,对手跟随球,而玩家则由用户输入控制。 所以我需要两个限制。
我需要创建一个只有球才能穿过的形状......这可能吗? 如果球越过球门线,也许我可以让对手睡着?
我以正确的方式处理这件事吗?
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用 Box2D,您可能想研究一下传感器。
摘自 Box2D 手册:
If you're using Box2D, you probably want to look into Sensors.
Taken from the Box2D Manual:
为什么不使用简单的碰撞检测?
如果在曲棍球场上移动的对象是球员类型,并且他的位置/击球区与球门碰撞,则您将他的位置更改回线,因此他可能无法与球门相交。
如果对象的类型不是玩家,您只需让对象通过
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
好吧,你不允许玩家向左或向右离开比赛场地,是吗?所以你只需要对球员的球门区域执行相同的逻辑即可。
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.