使用2D平台游戏hitTestPoint

使用2D平台游戏hitTestPoint

本文介绍了使用2D平台游戏hitTestPoint:故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我创建了自己的code对于2D平台游戏(如马里奥)。我决定使用hitTestPoint方法来处理我的碰撞。它的工作光滑如脂,一切工作完美。字符可以上下坡道完美。创建我的比赛将改变我的性格(这是一个块的时候)到人的性格可以到标有走,跳与立眼镜架是我的下一个步骤。这两个角色在创建变量后指出:运行和立I codeD性格去帧标签运行,如果向左或向右箭头键下降,而立如果字符没有运行,跳跃或下降。然后,code的工作还行,但也有认为正在发生如人品穿过墙壁随机运行和传送了坡道不少问题。我仍然有两个版本(工作和glitched)。除了人物的影片剪辑改变帧时,code没有改变。我绝对不知道为什么性格行事现在这个样子。如果任何人经历了一个问题,这样的前或知道这背后的问题,请帮助我!

So I created my own code for a 2d platform game (like Mario). I decided to use the hitTestPoint method to handle my collisions. It worked smooth as butter, and everything was working perfectly. The character could move up and down ramps perfectly.My next step in creating my game would be to change my character (which was a block at the time) into a human character that can go to frames labeled "walk", "jump" and "stand". After creating variables for the two character states "run" and "stand" I coded the character to go to frame label "run" if the left or right keys are down, and "stand" if the character is not running, jumping or falling. Then the code was working okay, but there were quite a few problems that were occurring such as the character randomly running through walls and teleporting up ramps.I still have both versions (working and glitched). Other than the character movie clip changing frames, the code was not altered. I have absolutely no idea why the character is acting like this now. If anyone has experienced a problem like this before or knows what the problem behind this is, please help me out!

德雷克Swartzy

Drake Swartzy

推荐答案

这是非常有可能你的样品是不够频繁(以实现您正在使用)来检测碰撞。

It's very likely your samples are not frequent enough (with the implementation you're using) to detect a collision.

通过一个足够低的频率,你会更新你的角色的位置,然后进行测试无论是重叠的目标。这意味着(如果你要足够快),你可以完全错过了碰撞。

With a low enough frequency, you'll update the position of your character, and then test whether it's overlapping the target. This means (if you're going fast enough) you could completely miss the collision.

有一个更好的方法可以使用​​光线投射。请参阅如何处理碰撞检测如此之快的物体是不允许穿墙?

A better approach may to use raycasting. See How do I handle collision detection so fast objects are not allowed to pass through walls?

这篇关于使用2D平台游戏hitTestPoint:故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 02:05