Just making characters in your game look around can bring them much more to life as well as express important information to the user. Here we’ll discuss a few use cases and present a script that makes it simple to implement in your game.

只需让游戏中的角色四处张望,就可以使角色栩栩如生,并向用户表达重要信息。 在这里,我们将讨论一些用例,并提供一个脚本,使您可以在游戏中轻松实现该脚本。

First a tech demo video to set the context:

首先是一个技术演示视频来设置上下文:

[vimeo clip_id=”5538153″ width=”640″ height=”480″]

[vimeo clip_id =” 5538153” width =” 640” height =” 480”]

As can be seen, the looking behavior works regardless of which animations are playing. (One problem though is that when the two hands are holding the gun together, they are not always properly coordinated, but that’s a problem to solve another time!)

可以看出,无论播放哪种动画,外观行为都有效。 (但是,一个问题是,当两只手将枪握在一起时,它们并不总是能正确地协调,但这是另一个需要解决的问题!)

Use Cases When two characters in a game are talking together (one of which might be a player avatar) they can look at each other to make the interaction look more sincere.

用例当游戏中的两个角色在一起聊天(其中一个可能是玩家的化身)时,他们可以互相看待,以使交互看起来更真诚。

When the avatar comes near a health pack, a weapon that can be picked up, or another important item, he could look at that item. Besides looking natural, this can also make the player more attentive to the item if she hadn’t noticed it herself.

当化身靠近医疗包,可以拿起的武器或其他重要物品时,他可以查看该物品。 除了看起来自然之外,这还可以使玩家在自己没有注意到的情况下更加专注于该项目。

When there’s nothing of particular interest nearby, simply making the character look around at different random points in space looks much more natural than just looking straight ahead. It can also express mood – if the character looks around only at points directly in front, he is probably pretty focused, while if he looks around to the sides and behind him too, he is probably more exploratory or searching around.

当附近没有什么特别有趣的事物时,简单地使角色在空间中的不同随机点处四处看看比直接往前看自然得多。 它也可以表达情绪-如果角色只在前方的某个位置四处张望,那么他可能会集中注意力,而如果他也四处张望并向后方注视,则他可能更具探索性或四处寻找。

Head Look Controller In between the main things we’re working one here at Unity, we sometimes get to do some projects on the side. In order to make it simple to make a character look at any point in space without requiring extra animations, I have made a head look controller script component as such a side project:

前视控制器在Unity的主要工作之间,有时我们需要在侧面进行一些项目。 为了使角色可以轻松地在空间中的任何位置看而无需额外的动画,我制作了一个头目控制器脚本组件,例如这样一个侧面项目:

Head Look Controller example project

Head Look Controller示例项目

Head Look Controller (script only) at Unify Community Wiki

Unify Community Wiki上的Head Look Controller(仅脚本)

This script can be used to make a character look towards a specified point in space, smoothly turning towards it with for example the eyes, head, upper body, or whatever is specified. Multiple ranges of bones can be specified, each with different settings for responsiveness, angle constraints etc.

该脚本可用于使角色朝空间中的指定点看,用例如眼睛,头部,上身或指定的任何物体平稳地转向该点。 可以指定多个范围的骨骼,每个骨骼具有不同的响应性,角度约束等设置。

In the video above the controller on the character is set up with one range of bones for the spine and one for the neck and head. Unfortunately the eyes of that character can’t turn, but that could be set up as well with an appropriately rigged character.

在上方的视频中,角色上的控制器设置为一根用于脊椎的骨头,另一根用于颈部和头部的骨头。 不幸的是,该角色的眼睛无法转动,但也可以通过适当地操纵该角色来进行设置。

Segments should always be specified with the bones/transforms closest to the root specified first and the ones deeper in the skeleton specified after that.

始终应使用最接近指定的根的骨骼/变形指定段,然后指定最接近的骨骼的深变形段。

Here’s the settings I used in for the component:

这是我用于该组件的设置:

只是随便看看

I have set the Threshold Angle Difference for the spine to 30, since the spine shouldn’t turn if the target angle (the angle between the direction towards the target and the direction straight ahead) is less than 30 degrees. The Bending Multiplier control how much the segment bends or turns compared to how big the target angle is. The segment will attempt to be no more than Max Angle Difference away from the target angle, though it won’t bend any further once it reaches the Max Bending Angle.

我已将脊柱的“ 阈值角度差”设置为30,因为如果目标角度(朝向目标的方向与笔直的方向之间的角度)小于30度,则脊柱不应转动。 弯曲倍增器控制线段与目标角度相比有多少弯曲或转弯。 该线段将尽力使其与目标角度的差不超过“ 最大角度差” ,尽管一旦达到“ 最大弯曲角度”就不会进一步弯曲

I set the responsiveness of the head segment higher than that of the upper body, since people tend to turn the head quicker. If segments had been specified for the eyes as well, they should have had an even higher responsiveness.

由于人们倾向于更快地转动头部,因此我将头部的响应速度设置为高于上身。 如果还为眼睛指定了细分,则它们应该具有更高的响应度。

I specified the left and right arm under Non Affected Joints, so that the arms keep keep pointing in the original direction despite the bending and turning of the upper body. By setting the Effect to 0.3 I let them be affected a little bit though.

我在“ 不受影响的关节”下指定了左臂和右臂,这样即使上半身弯曲和转动,手臂仍保持指向原始方向。 通过将“ 效果”设置为0.3,我会让它们受到一点影响。

The Head Look Vector and Head Up Vector are just used for reference to know the default alignment of the head. Per default they are set to forward (0,0,1) and up (0,1,0) respectively.

Head Look VectorHead Up Vector仅用作参考,以了解头部的默认对齐方式。 默认情况下,它们分别设置为正向(0,0,1)和向上(0,1,0)。

The Target point that the character should look at is specified through scripting.

通过脚本指定角色应查看的目标点。

“Pro Tips!” I said above that a character could look around at random points when there’s nothing else to look at. Actually, looking around at a few different points looks more natural in any case. Even when talking to a person or when having found an important object, people rarely tend to stare incessantly at the same point. Introduce more variation by looking at the main point of interest most of the time, but look away at some random points in space now and then.

“专业提示!” 我在上面说过,当没有其他事物可看时,角色可以在随机点四处张望。 实际上,无论如何,环顾几个不同的点看起来都更加自然。 即使在与人交谈或发现重要物体时,人们也很少会不断地盯着同一点。 大部分时间通过关注主要兴趣点来引入更多变化,但不时关注空间中的一些随机点。

And if your character supports it, don’t forget to blink once in a while! That is super-easy to do, either with a procedural script or with a traditional animation that only affects the eye-lids and which plays all the time at a higher layer than the other animations. Blinking a bit can really help make a character look less artificial, so if the eyes of a character are ever seen in your game, it’s worth spending the small amount of time it takes to implement.

如果您的角色支持,别忘了偶尔眨一下眼! 无论是使用程序脚本还是使用只影响眼睑并且始终在比其他动画更高的层次播放的传统动画,做到这一点非常容易。 稍微眨眼确实可以使角色看起来不那么虚假,因此,如果在游戏中看到过角色的眼睛,则值得花费少量时间来实现。

Go on! Make those characters more believable!

继续! 使这些角色更可信!

翻译自: https://blogs.unity3d.com/2009/07/10/just-looking-around/

相关文章: