您当前的位置: 首页 > 娱乐

阐述HTML5游戏中的角色移动设定

2018-11-01 10:03:06

阐述HTML5游戏中的角色移动设定

阐述HTML5游戏中的角色移动设定 |爪游控 首页多彩生活娱乐八卦汽车世界科技产业数码新品游戏动漫体坛风云军情解码社会万象健康养生 首页 / 游戏动漫 / 阐述HTML5游戏中的角色移动设定 阐述HTML5游戏中的角色移动设定 Posted on 2014年2月21日 by eva in 游戏动漫 作者:Mary Rose Cook近,我发布了我的2D射击/益智/平台游戏《Empty Black》。在本文中,我将介绍我们如何制作出灵活直观的角色移动。在看本文以前,读者能玩一玩《Empty Black》,以便更加理解我所说的内容。我的一般做法是,先改变一些东西,然后再实验。我的调整办法参考了若干种资源。一,我查看了其他2D平台游戏中的影响玩家角色移动的参数。比如,地面是否光滑?侧向移动对跳跃的比值是多少?角色是否加速移动?角色的跳跃高度是否受玩家按键时长的影响?角色撞上可移动的物体时是否会减速?图1(from webappers)二,我参考了其他2D平台游戏中的玩家角色的特殊行为。在《超级食肉男孩》中,角色抵墙而跳时会自动从墙上跳开。在《洞穴探险》中,角色可以越过平台。在《恶魔城》中,角色腾空时也可以再次跳跃。三,我让别人试玩。Kemal告诉我,角色移动应该很容易,特别是,如果角色撞到墙面时,角色应该跌倒。Ricky告诉我,玩家不能控制角色的跳跃高度,这太奇怪了。他演示给我看,当角色跃过在矮小的房间里的障碍物时, 角色的头撞上了天花板。Ricky还指出,当角色跳跃后着陆时,减速的效果很不好。所有人都告诉我腾空移动太敏感,以及墙跳太麻烦。四,我阅读了程序员写的关于角色移动算法的文章。那些文章主要是简短的评论,而不是深入的分析。因此,我才写了本文。对于算法,简短地说就是做一些小破解。详细地说,就是下面的内容:玩家按下跳跃键。个问题是:角色可以跳跃吗?这意味着:角色是否与任何可作为起跳点的物品接触?《Empty Black》使用Box2D控制游戏世界的物理。任何移动都受制于Box2D的摩擦力和重力模型。另外,Box2D会处理 碰撞物品的反应:反弹、推挤、旋转和滑动。游戏可以通过Box2D得知某个物品接触到了那一个物品。如果角色碰到的是坚固的物品,那么它就会跳起来。但是,跳跃的情况没有这么简单。角色不仅可以从地面起跳,也可以墙跳,也就是,角色先落在墙上,以之为立足点,再次跳离墙面。图2(from webappers)让角色跳出狭窄的垂直通道时经常使用这个技术。它使角色可以反复地在垂直、平行的墙面之间跃跳上升。图3(from webappers)这个能力是受限制的。玩家可能会跳离一个墙面后却又落在相同的墙面上。此时,角色可能就不能再次起跳了。如果玩家试图让角色再次起跳,角色就会摔下来。这里的反弹是为了改进玩法。如果我可以利用坚固墙面不能攀 爬的性质,那我就能轻易地设计出有趣的关卡。反弹使玩家更难决定角色是否有可靠的立足点。玩家应该能够随心所欲地让角色在地面上跳跃。但角色不能连续在相同的墙面位置上跳跃两次。幸运的是,Box2D有一个超自然物理对象来弥补墙体、敌人和子弹的不足,即传感器。这个灵体没有物理实体。它存在于空间中,能够暂时储存碰撞运动。程序员可以通过它了解碰撞,就像通过有形实体一样。我要做的就是,给角色的按键附加一个宽泛而短时的传感器。如下图所示:图4(from webappers)注意,传感器与地面重叠。现在,游戏不需要通过角色对象感知碰撞活动,而是通过角色的按键传感器。那有什么帮助?没有。但我可以在一个角色上添加另外两个传感器,一边一个。图5(from webappers)这意味着游戏可以通过传感器得知角色是否接触到其他物品。如果按键传感器接触到可作立足点的坚固实体,那么角色就可以起跳。如果只有一边的传感器接触到坚固实体,那么游戏就会进一步调查。除了以下两种情况,角色都可以跃跳。一,角色落在他刚刚才起跳的墙面位置上。图6(from webappers)游戏会保留传感器感知到的一次起跳点的记录。如果是一边的传感器,且角色使用相同的传感器记录当前的立足点,那么角色就不能再次起跳了。如果玩家在角色墙跳上升时松开控制键,角色就会开始下落。玩家在角色下落到墙面时可能会按起跳键。有可能此时的墙面正是角色刚才起跳的墙面。如果是,那么角色将无法起跳。然而,有一个例外,如果角色的位置比上一次跃跳的位置低,那么他就仍可以起跳。这个例外让玩家得以弥补自己的操作失误,使操作更加人性化。二,角色着陆并暂时停留在墙面上。玩家继续按方向键,使角色抵在墙面上,然后再按跃跳键。这时,角色是不允许起跳的。此时,角色将会做出如下图所示的滑行动作:图7(from webappers)为了停止角色的滑行,如果玩家没有把角色按在墙上的话,游戏就允许角色起跳。有一个例外:如果角色接近墙面顶部,角色就可以跃跳。此时,角色会沿着墙面上滑行。图8(from webappers)游戏现在知道角色是否允许跃跳了。为了响应跃跳,上向的力量是瞬间产生的。当角色刚开始移动时,它的速度会很快。由于重力作用,这个速度会逐渐变慢。当角色腾空到某一段高度,向上的力量就会完全消失,角色随之 开始下落。如果玩家在角色达到跃跳的高度以前松开跃跳键,那么角色就会马上下落。这个想法我借鉴了《超级食肉男孩》。如果角色跳得太高,结果就会是,玻璃天花板插入角色的头部。这使得玩家不得不控制好跃跳的高度,以免角色撞个头破血流。跃跳力量的大小通常是恒定的。然而,在以下两种情况中,这个力量会增加。一,当角色携带板条箱时。这使得负重角色无法跃跳,而变成笨拙的兔子跳。二,当角色比通常情况更快下落时。想象一下,角色正要墙跳,因为玩家的笨拙,角色落到的墙面位置比刚才的起跳点低。为了帮助玩家弥补这个失误,角色接下来的墙跳力量会比正常情况下的大。这股力量与正常力量的差距和正常下落的力量与实际下落的力量之间的差距成正比。现在,再说说侧边移动。玩家按下左方向键。然后呢?角色会持续产生一股向左的力量,直到玩家松开方向键。这股力量的大小取决于角色当前移动的速度。如果角色的速度达到,那就不会产生力量。如果角色是静止的,那么这股力量就会很大。这个操作的关键是,尽可能快地让角色达到速度,然后保持速度。这使得玩家更容易预测到角色的移动,还解决了Ricky提出的第二个问题。角色在起跳后立即获得速度。玩家松开左方向键。然后呢?角色会马上停止。不会产生惯性。所以,玩家会更容易控制角色。当我在设计角色的移动时,我发现很难保持整齐的代码。我努力寻找少的、不需要后续调整的规则。两个例子。一,我试图通过设置非常高的摩擦力来消除地面的光滑度。但这么做产生了许多不理想的结果。在不使腾空移动非常敏感的情况下,玩家很难使角色以速度进行侧边移动。板条箱不能推挤,玩家如果扔错了地方,可能使它卡在平台上。我添加代码,使玩家松开移动键时,角色会立即停止。二,在平台上滑行只出现在玩家在角色接近墙顶时按下跃跳键时。但如果角色距离墙面还有一段距离,那么跃跳意味着角色会向上滑行然后暂停。我本可以把这个问题放着不管。但那会使玩家很难操作角色的墙跳。我本可以角色自动地跳离墙面。但那么做好像太落伍了。所以,当玩家使角色贴墙,且不在墙顶附近时,不允许角色跃跳。在这两种情况下,应该用一个丑陋但无影响的小破解来稍微调整通常正确的行为。我的一般方法是,多尝试多探索各种选择。但我的目标是普遍的规则。我的做法是,在仔细检查各个分支选项后确定性变更。有时候,我会完全重制规则,因为我给角色添加了传感器。做个总结。查看其他游戏中的角色的整体行为和特定参数。尽量收集玩家反馈。做多次变更并整理清楚。(转自)Deft and Intuitive Character Movement in HTML5 Gamesby Mary Rose CookThis article recently appeared on , a collaboration by the teams at Bocoup and Internet Explorer. Recently, I released Empty Black, my 2D shooter/puzzler/platformer. In this article, I’ll describe how I made the player movement deft and intuitive. Play the game before you read on, so you’ll know what I’m talking general approach was to change something, then try it out. I took the ideas for adjustments from several e. I examined the parameters affecting the movement of the player characters in other 2D platformers. Is the floor slippy? What is the ratio of sideways movement to jump height? Does the character accelerate as it moves? Is the character’s jump height affected by the length of time the player holds the jump button? Is the character slowed when it bumps into a moveable object?Two. I examined the unusual behaviours of the player characters in other 2D platformers. Super Meat Boy makes the character leap away from the wall automatically when wall-jumping. Spelunky lets the character pull himself up and over ledges. In Castlevania, the character can do an extra jump while in ree. I got people to play test. Kemal told me that the character movement should be effortless. Specifically, if the character hits a wall near the top, it should slip up and over. Ricky told me it was weird that the player had no control over the height of the character’s jump. He showed me how, when hopping over an obstacle in a room with a low ceiling, he bumped his head. Ricky also pointed out the jarring effect of the initial slow down of the character when it lands after a jump. Everyone told me that airborne movement was too sensitive. Everyone told me that wall-jumping was too ur. I read pieces written by programmers about their character movement algorithms. These pieces were mostly confined to short comments, rather than in-depth analyses. Hence, this the e short version: a pile of e long version:The player presses the jump key. The first question is: can the character jump? Which means: is the character in contact with anything that can be used as a place to jump from? Empty Black uses Box2D to control the physics of the game world. Any movements are subject to Box2D’s models of the forces of friction and gravity. Further, Box2D handles the reactions of objects that collide: bounces, shoves, spins and slides. The game can interrogate Box2D and ask what objects a particular object is touching. If the character is currently touching something solid, the character may cept, it’s not quite that simple. As well as leaping from the ground, the character can wall-jump. This means landing and clinging onto a wall, then jumping again, away from the is technique is used frequently as a way for the player to get the character up a narrow shaft. They jump it back and forth between the vertical, parallel walls of the shaft, ascending with each is ability is bounded. The player may jump the character out from a wall and land it on the same wall. At this point, it may not jump again. If the player tries to make it jump, the character will fall. This bound is there to improve the gameplay. It is easier to design fun levels if I can rely on the unscalable nature of a solitary e bound makes it harder to decide if the character has a solid footing. The character should be able to jump from the ground as many times as the player likes. But it should not be able to jump from the same wall twice in a rtunately, Box2D has a metaphysical object that complements the corporeal walls, enemies and bullets: the sensor. This spiritual creature has no physical presence. It has a location in the world and it registers collisions. The programmer can interrogate it about such collisions, just as with physical at I did was to attach a wide, short sensor to the bottom of the character. It would look like this, if you could see it:Notice how the sensor overlaps the w, instead of asking the character object about collisions, the game asks the character’s bottom w does that help? It doesn’t. But I can attach two more sensors to the character, one on each of its is means that the game can ask each sensor if it is touching anything. If the bottom sensor is touching some solid footing, jumps are always allowed. If only a side sensor is touching a solid footing, the game must investigate further. Jumps will be allowed in all cases but e. The character lands against the wall it has just jumped e game keeps a record of the last sensor that registered the solid footing for a jump. If it was a side sensor, and the character is using the same sensor for registration of the current solid footing, the jump is not the player loses control during a wall-jump ascent, the character will begin to fall. The player might manage to press jump as it hits a wall on its way down. It is possible that this wall will be the one they most recently jumped from. If it is, the jump would be prevented. However, there is an exception that permits the jump if the character is lower than it was when it jumped the time before. This exception allows the player to recover from their mistake. It makes the controls more o. The character lands and sticks to the wall. The player continues to press the direction key that holds the character against the wall. They press jump again. The jump is not allowed. If it were, the character would slide up the wall like this:To stop this, the game only allows the jump if the player is not pressing the character into the wall. There is an exception. If the character is near the top of a wall, it may jump. This lets it slip up and over the e game now knows if the character is allowed to jump. To enact the jump, upward force is applied for a single instant. The character’s velocity is high when it first starts moving. It is progressively attenuated by gravity. Some distance into the air, all the character’s momentum will be gone and it will begin the player releases the jump button before the character has reached its peak in the jump, the character will immediately begin falling. I stole this idea from Super Meat Boy. The effect is that of a glass ceiling being inserted above the character’s head. This allows the player to control the height of the jump. It stops Ricky getting a sore e magnitude of the force of the jump is usually constant. However, it is increased in two rst, when the character is carrying a crate. This stops the weighted character’s jumps turning into lame little bunny cond, when the character is falling faster than usual. Imagine the character is wall-jumping and, because of a player fumble, it hits the next wall at a point lower than the point it jumped from. To help the player recover, their next attempt at a jump from a wall will lift the character with a force greater than normal. The difference from the normal force is proportional to the disparity between the normal and actual force of w: sideways e player presses the left arrow key. What happens?A leftward force is continually applied until the player releases the key. The magnitude of the force depends on how fast the character is currently moving. If it is at top speed, no force is applied. If it is stationary, a large force is applied. The idea is to get the character to top speed as fast as possible, then hold it at that speed. This makes the movement more predictable. It also solves Ricky’s second problem. The character immediately regains top speed after it lands a e player releases the key that moves the character left. What happens?The character immediately stops. There is no slippiness. Thus, the character is easier to en I was designing the character movement, it was hard to keep the code tidy. I tried to find the smallest number of rules that required the least subsequent modification with o e. I tried to eliminate the slippiness of the floor by setting the friction very high. But this had many undesired consequences. It was hard to get the player moving sideways at top speed without also making airborne movement too sensitive. Crates could no longer be shoved, and mis-throws would leave them perched on ledges. I added code to immediately stop the character upon release of the move o. Slipping up and over a ledge was just a matter of the player pressing the jump key near the top of a wall. But if the character was only half way up a wall, such a jump would mean it slid upwards and got stranded. I could have left that behaviour as it was. But that would have made wall-jumping harder. I could have automatically jumped the character away from the wall. But that seemed too nannyish. So, I prevented jumps when the player was pressing into the wall but was not near the top of both cases, it was worth slightly modifying a generally correct behaviour with an ugly but small hack that had no e general approach was to try stuff to explore the options. But the goal was a few broad rules. I did this by only deciding on a permanent change after a careful check of the ramifications. And I sometimes entirely remade the rules, as with the addition of the sensors to the re is a pocket-sized summary for amine the overall behaviours and specific parameters of other games. Get as much player feedback as you can. Make many changes. Tidy up after yourself.(source:webappers) 文章导航Previous Previous post: 手游和主机游戏研发应互相学习什么?下一条 Next post: 张柏芝、谢霆锋和王菲,怎么都能在一起! 本站CDN由UPYUN又拍云强力驱动. 关于我们 | 加入我们 | 联系我们 | 版权声明 © 爪游控 版权所有. 陕ICP备号-1 Top

空气悬浮风机
男童演出服
塑料托盘厂家
推荐阅读
图文聚焦