如何让unity mesh colliderr碰撞移动CharacterController

阅读:4825回复:12
CharacterController.isGrounded是否碰撞地面的问题???
发布于: 15:23
.isGrounded就算是接触地面了,返回的也是在真和假之间。
求怎么解决!!!
我已经添加了重力的变种!!
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 18:17
自己顶一下!
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 14:25
CharacterController 已经封装了重力,所以你不用在添加重力了。是否接触到地面? 一般用来判断角色是否在空中。。。
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 15:20
:CharacterController 已经封装了重力,所以你不用在添加重力了。是否接触到地面? 一般用来判断角色是否在空中。。。 貌似是在CharacterController 的simplemove函数中封装了重力,但是在move函数中没有吧!!而且最最主要的就是当CharacterController 移动的时候isGrounded就是false只有静止的时候是true。我想要的是只要接触地面就返回true应该怎么做??谢谢
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 16:13
是啊,isGrounded碰撞到地面并且稳定站在地面上,true和false之间飘忽不定啊,没解决!!!!!!s:6]
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 23:01
刚才试验了一下,用射线碰撞代替CharacterController.isGrounded吧,谁知道这是UNITY3D的BUG,还是哪的毛病,希望高手能解决CharacterController.isGrounded飘忽不定的判断
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 00:12
&&怎么飘忽不定
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 06:19
一会是true ,一会是false,仔细观察一下角色,发现如果角色在Idle时来回晃悠就会出现这种情况,于是乎换个不晃悠的角色,发现真假不来回自动随机切换了,但始终是FALSE,晕,此时发现角色碰撞器和地面有一定的距离,在把角色手动把角色碰到地面上,在测试,角色又回到原来的位置,也就是始终和地面有一定距离,当人物走动时处于腾空状态。这种情况显得极不真实,最重要的是需要CharacterController.isGrounded 来判断跳跃啊,因为呈现的是假,所以跳跃不正常,只能用射线来代替这个句语了,但角色和地面脱空始终没解决!!!好累,打字太多了,手麻了
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 13:25
:一会是true ,一会是false,仔细观察一下角色,发现如果角色在Idle时来回晃悠就会出现这种情况,于是乎换个不晃悠的角色,发现真假不来回自动随机切换了,但始终是FALSE,晕,此时发现角色碰撞器和地面有一定的距离,在把角色手动把角色碰... 这两个字也会手麻,估计是美工出身charactorController有个skinWidth属性,这个值会导致碰撞器在和其他collider接触时保持一定间隙,不知道你有没有考虑到这个因素
<span class="lou J_floor_copy" title="复制此楼地址"
data-hash="read_楼#
发布于: 17:50
确实如此,非常感谢!版主终究是版主,很厉害
您需要登录后才可以回帖,&或者&
Powered byCharacterController 角色控制器
Inherits from
A CharacterController allows you to easily do movement constrained by collisions without having to deal with a rigidbody.
角色控制器允许你在受制于碰撞的情况下很容易的进行运动,而不用处理刚体。
(个人理解:用CharacterController组件,它包含Rigidbody组件的一些属性,就不用用Rigidbody组件了)。
A CharacterController is not affected by forces and will only move when you call the Move funtion.
It will then carry out the movement but be constrained by collisions.
角色控制器不受力的影响,仅仅当你调用Move函数时才运动。然后它将执行运动,但是受制于碰撞。
摘自网络的Physx参考:
character一般用于主角这类用户控制的物体,它不会受到scene的重力影响,不会被其他物体推。
程序中可以使用它的move方法移动它,当他碰到静态物体时,会停下来,遇到动态物体时会推开他,当然,这些都是可以通过activegroup来控制的。group最多有32组。因为他是一个NxU32,并通过每一位代表一个组。
move的一个参数用来告诉程序,character的当前状态。(collisionFlags)
当他遇到物体的时候,如果设置了回调函数,系统会通过回调函数通知程序。。(NxControllerDesc.callback)
character还有上楼梯模式,在某些高度的台阶,可以直接上去。(NxControllerDesc.stepOffset)
character还可以设置可以走上去的斜坡。(NxControllerDesc.slopeLimit)
由于character不受场景的重力影响,所以,用户要在move函数中自己添加重力因素,也就是说,character可以浮在空中,除非那里有其他activegroup物体。
Variables变量
Was the CharacterController touching the ground during the last move?着地
在最后的移动角色控制器是否触碰地面?
The current relative velocity of the Character (see notes).角色当前的相对速度(参见注解)。
What part of the capsule collided with the environment during the last CharacterController.Move call.在最后的CharacterController.Move调用期间,胶囊体的哪个部分与周围环境相碰撞。
The radius of the character's capsule 角色胶囊体的半径。
The height of the character's capsule角色胶囊体的高度。
The center of the character's capsule relative to the transform's position.相对于变换位置的角色胶囊体的中心
The character controllers slope limit in degrees角色控制器的坡度度数限制。
The character controllers step offset in meters
以米为单位的角色控制器的台阶偏移量(台阶高度)。
Should other rigidbodies or character controllers collide with this character controller (By default always enabled)
其他的刚体和角色控制器是否能够与本角色控制器相碰撞(默认值通常是enabled)
Functions函数
Moves the character with speed.以一定的速度移动角色。
A more complex move function taking absolute movement deltas.
一个更加复杂的移动函数,每次都绝对移动。
Messages Sent发送消息
OnControllerColliderHit is called when the controller hits a collider while performing a Move.控制器碰撞器相碰
当控制器碰撞一个正在运动的碰撞器时,OnControllerColliderHit 被调用。
Inherited members继承成员
Inherited Variables继承变量
Enabled Colliders will collide with other colliders, disabled Colliders won't.
启用碰撞器将会碰撞其他碰撞器,禁用碰撞器就不会碰撞其他碰撞器。
The rigidbody the collider is attached to.
碰撞器附加的刚体。
Is the collider a trigger?
碰撞器是一个触发器? (是否可以穿越)
The material used by the collider.
撞器使用的材质。
The shared physic material of this collider.
碰撞器的共享物理材质。
The world space bounding volume of the collider.
碰撞器在世界坐标空间的边界框。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(Read Only). (null if there is none attached)
附加到(游戏物体)(只读)(如无附加则为空)。
attached to this
(Read Only). (null if there is none attached)
附加到(游戏物体)(只读)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
The game object this component is attached to. A component is always attached to a game object.
组件附加的游戏物体。一个组件总是被附加到一个游戏物体。
The tag of this game object.
游戏物体的标签。
The name of the object. //物体的名字
Should the object be hidden, saved with the scene or modifiable by the user?
物体是否被隐藏、保存在场景中或被用户修改?
Inherited Functions继承函数
The closest point to the bounding box of the attached collider.
到附加碰撞器的边界框最近的点。
Casts a Ray that ignores all Colliders except this one.
投射一个光线(),它忽略所有碰撞器,除了这个。
Returns the component of Type type if the game object has one attached, null if it doesn't.
如果游戏物体有一个附加,则返回Type类型的组件,如果没有则为null。
Returns the component with name type if the game object has one attached, null if it doesn't.
如果游戏物体有一个附加,则返回名字类型组件,如果没有则为null。
Returns the component of Type type in the
or any of its children using depth first search.
返回Type类型组件,在或它的任何子物体使用深度优先搜索,仅返回激活的组件。
Returns all components of Type type in the
or any of its children.
在或任何它的子物体,返回全部Type类型组件
Returns all components of Type type in the .
在游戏物体返回全部Type类型组件。
Is this game object tagged tag?
游戏物体有被标记标签么?
Calls the method named methodName on every
in this game object and on every ancestor of the behaviour
在游戏物体每一个和每一个behaviour的祖先上调用名为methodName的方法。
Calls the method named methodName on every
in this game object.
在游戏物体每一个上调用名为methodName的方法。
Calls the method named methodName on every
in this game object or any of its children.
在游戏物体每一个和它的全部子物体上调用名为methodName的方法。
Returns the instance id of the object.
返回物体的实例ID
Returns the name of the game object.返回游戏物体的名称。
Messages Sent发送消息
OnTriggerEnter is called when the Collider other enters the trigger.
当碰撞器other进入触发器时OnTriggerEnter被调用。
OnTriggerExit is called when the Collider other has stopped touching the trigger.
当碰撞器other停止触动触发器时,OnTriggerExit被调用。
OnTriggerStay is called almost all the frames for every Collider other that is touching the trigger.
每个碰撞器other触动触发器,几乎在所有的帧OnTriggerStay被调用。
OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
当collider/rigidbody开始触动另一个rigidbody/collider时OnCollisionEnter被调用。
OnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.
当 collider/rigidbody停止触动另一个 rigidbody/collider时,OnCollisionExit被调用。
OnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.
每个collider/rigidbody触动rigidbody/collider,将在每帧调用OnCollisionStay。通俗的说,
Inherited Class Functions继承类函数
Removes a gameobject, component or asset.
删除一个游戏物体、组件或资源
Destroys the object obj immediately. It is strongly recommended to use Destroy instead.
立即销毁物体obj,强烈建议使用Destroy代替。
Makes the object target not be destroyed automatically when loading a new scene.
加载新场景的时候使目标物体不被自动销毁。
Returns the first active loaded object of Type type.
返回Type类型第一个激活的加载的物体。
Returns a list of all active loaded objects of Type type.
返回Type类型的所有激活的加载的物体列表
Clones the object original and returns the clone.
克隆原始物体,并返回克隆的物体
本脚本参考基于Unity 3.4.1f5英文部分版权属&公司所有,中文部分&
版权所有,未经许可,严禁转载 。Unity3D脚本教程7:碰撞描述类 collision
日&&&&评论:&&&
&&& 来源:
&&& 碰撞描述类 collision
&&& Collision 信息被传递到Collider . OnCollisionEnter , Collider . OnCollisionStay和Collider.OnCollisionExit事件。参见: ContactPoint.
&&& ◆var collider : Collider&&& //& 描述:碰撞到的Collider ( 只读 ).为了得到所有被碰撞到的碰撞器的细节,你需要迭代接触点( contacts属性)。
&&& ◆var contacts : ContactPoint [ ]&&& //& 描述:接触点由物理引擎产生。每个contact包含一个接触点,法线和两个发生碰撞的碰撞器(参考ContactPoint)。在OnCollisionStay或者OnCollisionEnter内可以确保contacts有至少一个元素。&&& function OnCollisionStay ( collision : Collision ){
&&& for ( var contact : ContactPoint in collision . contacts ) //检查碰到碰撞器是否有刚体&&& {
&&& print ( contact.thisCollider . name + "hit" + contact . otherCollider .name );&&& //检查碰到碰撞器是否有刚体
&&& Debug.DrawRay ( contact . point , contact . normal, Color .white ) ;& //可视化接触点&&& }&&& }
&&& var explosionPrefab : T&
&&& function OnCollisionEnter( collision : Collision ) //一枚手榴弹,在击中一个表面时初始化一个爆炸预设,然后销毁它
&&& { &&&& var contact = collision . contact [ 0 ];&&&&
&&&& var rot = Quaternion . FromToRotation ( Vector3.up , contact . normal ) ;
&&&& var pos = contact .
&&&& Instantiate ( explosionPrefab , pos , rot ) ;//&& 旋转这个物体使y轴面沿着表面法线的方向
&&&& Destory ( gameObject );//销毁这个投射物
&&& ◆var gameObject : GameObject&&& //&& 描述:/ gameObject / 是与之碰撞的物体(只读)
&&& ◆var relativeVelocity : Vector3&&& //&&& 描述: 两个碰撞物体的相对线形速度(只读)。
&& function OnCllisionEnter ( collision : Collision )& &&& {
&&& if ( collision . relativeVelocity . magnitude & 2 )//当以较大的速度碰到一个物体时播放声音
&&& audio .Play ( );&&& }
&&& ◆var rigibody : Rigidbody&&&&& //&&& 描述:碰撞到的Rigidbody(只读),如果碰到的物体是一个没有附加刚体的碰撞器,返回null
&&& function OnCollisionStay ( collision : Collision ) {
&&& if ( collision . rigidbody )&&& //检查碰到的碰撞器是否有一个刚体 ,然后使用力&&& {
&&& collision . rigidbody .AddForce ( Vector3 . up * 15 ) ;&&& //让所有碰到的刚体向上飞
&&& }&&& }
&&& ◆var transform : Transform& //& 描述:碰撞到的物体的Transform(只读)。如果碰到一个带有Rigidbody的碰撞器,transform将是所有附加刚体的变换。如果碰到了一个没有刚体的碰撞器,transform将是所有附加碰撞器的变换。
&&& 碰撞接触点结构 ContactPoint
&&& ContactPoint 碰撞发生的接触点。接触点被存储在collision结构中,参见collision , collision . OnCollisionEnter,&&&&&&& Collision . OnCollisionStay& , Collision . OnCollisionExit.
&&& ◆var normal : Vector3&&& //&& 描述:接触点的法线
&&& ◆var otherCollider : Collider&&& //&&& 描述:碰撞中的另一个碰撞器
&&& ◆var point : Vector3& //&& 描述:接触点
&&& ◆var thisCollider : Collider&#61557;&&& //& 描述:碰撞中的第一个碰撞器
&&& ControllerColliderHit& 类
&&& ControllerColliderHit被CharacterController . OnControllerColliderHit使用来给出详细的关于碰撞和如何处理它们的信息。
&&& ◆var collider : Collider&&& //&&& 描述:被控制器碰到的碰撞器。
&&& ◆var controller : CharacterController&& //&& 描述:碰到该碰撞器的控制器。
&&& ◆var gameObject : GameObject&&& //&&& 描述:被控制器碰到的游戏物体。
&&& ◆var moveDirection : Vector3&&& //&&& 描述:从胶囊的中心到接触点的大致方向。这可以用来找到一个合理的方向将力应用到接触的刚体。
&&& ◆var moveLength : float&&& //& 描述:角色碰到这个碰撞器时已经行走了多远。注意这可能不同于你传递到CharacterController . Move的。因为所有的移动都是被碰撞器制约的。
&&& ◆var normal : Vector3&&& //&&& 描述:在世界空间中碰撞表面的法线。
&&& ◆var point : Vector3&&& //&&& 描述:世界空间中的碰撞点。
&&& ◆var rigidbody : Rigidbody&&& //&&& 描述:被控制器碰到的刚体。如果没有接触一个刚体而是一个静态碰撞器时为null。
&&& ◆var transform : Transform& ///&&& 描述:被控制器碰到的变换
标签:上一篇:下一篇:
网友评论:Unity3D脚本教程7:碰撞描述类 collision评论条
您可能还需要关注一下内容:··········
商家:商家:商家:商家:商家:商家:商家:商家:
第三维度信息技术有限公司 版权所有
Beijing The third dimension Inc. All Rights Reserved.
24小时电话:求大神指教:CharacterController与Rigidbody两个组件的关系_unity3d吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:29,492贴子:
求大神指教:CharacterController与Rigidbody两个组件的关系收藏
今天下午碰到个问题纠结了很久:人物加上了Rigidbody并使用了重力,遇到悬崖居然不掉下,如履平地地走了过去。想了很久又请教了别人,花了很长时间才发现,CharacterController与Rigidbody两个组件有冲突。Unity圣典中的说法是: 角色控制器允许你在受制于碰撞的情况下很容易的进行运动,而不用处理刚体。(个人理解:用CharacterController组件,它包含Rigidbody组件的一些属性,就不用用Rigidbody组件了)。
角色控制器不受力的影响,仅仅当你调用Move函数时才运动。然后它将执行运动,但是受制于碰撞。下面说说我自己的理解,有不足之处请大神指教:1.添加了CharacterController组件后,人物将不受力影响,这时即使加上Rigidbody组件,并启用Use Gravity,人物也不会受重力影响,在脚本中通过rigidbody对人物施加力也是无效的。也就是说CharacterController屏蔽了Rigidbody的所有属性和方法。要控制CharacterController移动,可以通过在脚本中调用Move方法使其移动。2.虽然CharacterController不受力,但是有个例外是,它受碰撞的影响。一般的碰撞发生条件是:碰撞的两个物体必须都有Collider,并且其中一个有Rigidbody。但是如果一方有CharacterController,则不需要。这时碰撞发生的条件为:一方有CharacterController,另一方有Collider。CharacterController本身就继承自Collider。3.碰撞发生时,CharacterController不会推动其它物体移动,也就是说CharacterController不会对它所碰撞的物体施加物理作用。除非我们在脚本中添加了OnControllerColliderHit()函数,在该函数中使用被碰撞物体的rigidbody对被碰撞物体施加力。
我觉得。。。。。。写得非常好呢。。。。。。
还有几个小补充:CharacterController只能y轴旋转。CharacterController使用move移动的时候,比普通的transform.Translate的计算量大得多,尽量的只用在主角上。CharacterController实时的改变半径或者高度的时候很容易碰撞失效双方都是CharacterController时,OnControllerColliderHit()对双方好像都不起作用
其实我理解的是CharacterController只是一个专门对"人"的碰撞,没什么特别的,仅仅比Capsule collider多了几个属性而已,至于不受重力和Rigidbody物理性,这是由于人物控制函数(比如move函数决定脚底碰撞,重力等)影响的,和CharacterController有关系么
使用CharacterController有一个很不爽的地方就是: 使用SimpleMove函数进行移动的时候
若 使得角色仅沿着某一轴象进行移动 比如仅沿着x轴向进行移动 那么 当你又想要进行角色旋转控制的时候,你会发现 当角色旋转后 对角色进行移动的时候 角色依旧是沿着原来的x轴向进行移动 换句话说就是 不管角色有没有旋转 角色永远都是沿着一个轴向进行移动的 只不过面的朝向改变了而已
这点 使用起来很不爽
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或&#xe621; 上传我的文档
&#xe602; 下载
&#xe60c; 收藏
该文档贡献者很忙,什么也没留下。
&#xe602; 下载此文档
正在努力加载中...
Unity3d面试题总结
下载积分:5000
内容提示:Unity3d面试题总结
文档格式:DOC|
浏览次数:5|
上传日期: 09:08:56|
文档星级:&#xe60b;&#xe612;&#xe612;&#xe612;&#xe612;
该用户还上传了这些文档
Unity3d面试题总结
官方公共微信}

我要回帖

更多关于 collider 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信