unity3d 2d弯曲通道怎么加unity2d碰撞检测代码

你正在使用的浏览器版本过低,将不能正常浏览和使用知乎。问题补充&&
本页链接:
可以在碰撞时尝试判断角色的高度值来确定是否触发踩死或者被碰死.
jimode**zou &
•••••••••••
你可以加collider2D,在你需要检测的一侧另外加一个来做检测。希望对你有用!
这么简单 加2个collider就OK了
去看《unity3d手机游戏开发》吧!上面有!!!
猜你感兴趣工具修订记录最近更改媒体管理器网站地图登录注册&
UnityEngine
UnityEngine.SceneManagement
场景管理类
script:unityengine:classes:collider2d:collider2d
Collider2D 二维碰撞器
Namespace: UnityEngine
Inherits from:
Description 描述
Parent class for collider types used with 2D gameplay.
2D游戏碰撞器类型的父类。
Variables 变量
The Rigidbody2D attached to the Collider2D's GameObject.
Rigidbody2D附加到该Collider2D的游戏对象上。
The world space bounding area of the collider.
碰撞器的世界空间边界区域。
TThe density of the collider used to calculate its mass (when auto mass is enabled)
碰撞器的密度用来它的质量(当自动质量启用)。
Is this collider configured as a trigger?
这个碰撞器被配置作为一个触发器?
The local offset of the collider geometry.
该碰撞器几何体的局部偏移。
The number of separate shaped regions in the collider.
该碰撞器上单独图形区域的数量。
The PhysicsMaterial2D that is applied to this collider.
应用到这个碰撞器的PhysicsMaterial2D 。
Whether the collider is used by an attached effector or not.
是否该碰撞器用于效果器。
Functions 函数
Check if a collider overlaps a point in space.
在世界空间检查碰撞器重叠的一个点。
Check whether this collider is touching the collider or not.
检测该碰撞器是否正触摸的碰撞器。
Checks whether this collider is touching any colliders on the specified layerMask or not.
检测该碰撞器是否是触摸指定层蒙版的碰撞器。
Messages 消息
Sent when an incoming collider makes contact with this object's collider (2D physics only).
当传入的碰撞器接触到这个对象的碰撞器时发送(仅2D物理)。
Sent when a collider on another object stops touching this object's collider (2D physics only).
当另一个对象上的碰撞器停止接触这个对象的碰撞器时发送(仅2D物理)。
Sent each frame where a collider on another object is touching this object's collider (2D physics only).
当另个对象的碰撞器正在触碰这个对象的碰撞器时,每帧发送(仅2D物理)。
Sent when another object enters a trigger collider attached to this object (2D physics only).
当另个对象的碰撞器进入到这个对象的触发碰撞器时发送(仅2D物理)。
Sent when another object leaves a trigger collider attached to this object (2D physics only).
当另个对象的碰撞器离开这个对象的触发碰撞器时发送(仅2D物理)。
Sent each frame where another object is within a trigger collider attached to this object (2D physics only).
当另个对象的碰撞器停留在这个对象的触发碰撞器内时每帧发送(仅2D物理)。[Unity3D]射线碰撞检测+LayerMask的使用&转
射线:射线是3D世界中一个点向一个方向发射的一条无终点的线,在发射轨迹中与其他物体发生碰撞时,它将停止发射&。
用途:在unity中射线应用范围比较广,&多用于碰撞检测(如:子弹飞行是否击中目标)、角色移动
1、Ray&Camera.main.ScreenPointToRay(Vector3&pos)&&&返回一条射线从摄像机到屏幕指定一个点
2、Ray&Camera.main.ViewportPointToRay(Vector3&pos)&&返回一条射线从摄像机到视口(视口之外无效)指定一个点
3、Ray&射线类&
4、RaycastHit&光线投射碰撞信息
5、bool&Physics.Raycast(Vector3&origin,&Vector3&direction,&float&distance,&int&layerMask)
& 当光线投射与任何碰撞器交叉时为真,否则为假。
&&bool&Physics.Raycast(Ray&ray,&Vector3&direction,&RaycastHit&out&hit,&float&distance,&int&layerMask)
& 在场景中投下可与所有碰撞器碰撞的一条光线,并返回碰撞的细节信息()。
&&bool&Physics.Raycast(Ray&ray,&float&distance,&int&layerMask)
& 当光线投射与任何碰撞器交叉时为真,否则为假。
&&bool&Physics.Raycast(Vector3&origin,&Vector3&direction,&RaycastHit&out&hit,float&distance,&int&layerMask)
& 当光线投射与任何碰撞器交叉时为真,否则为假。
&&注意:如果从一个球型体的内部到外部用光线投射,返回为假。
& 参数理解:
  origin&:&在世界坐标中射线的起始点
  direction:&射线的方向
  distance:&射线的长度
  hit:&使用c#中out关键字传入一个空的碰撞信息类,然后碰撞后赋值。可以得到碰撞物体的transform,rigidbody,point等信息。&
  layerMask:&只选定Layermask层内的碰撞器,其它层内碰撞器忽略。&选择性的碰撞
6、RaycastHit[]&RaycastAll(Ray&ray,&float&distance,&int&layerMask)
&&&投射一条光线并返回所有碰撞,也就是投射光线并返回一个RaycastHit[]结构体。
列子如下:
using&UnityEngine;
using&System.Collections;
public&class&RayTest&:&MonoBehaviour&{
&&&&//&Use&this&for&initialization
&&&&void&Start&()
&&&&&&&&mainCrma&=&Camera.main;
&&&&private&Camera&mainCrma;
&&&&private&RaycastHit&objhit;
&&&&private&Ray&_ray;
&&&&void&Update&()&
&&&&&&&&if&(Input.GetMouseButtonDown(0))&
&&&&&&&&&&&&_ray=mainCrma.ScreenPointToRay(Input.mousePosition);//从摄像机发出一条射线,到点击的坐标
&&&&&&&&&&&&Debug.DrawLine(_ray.origin,objhit.point,Color.red,2);//显示一条射线,只有在scene视图中才能看到
&&&&&&&&&&&&if&(Physics.Raycast&(_ray,&out&objhit,&100))&
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&GameObject&gameObj&=&objhit.collider.gameObject;
&&&&&&&&&&&&&&&&Debug.Log("Hit&objname:"+gameObj.name+"Hit&objlayer:"+gameObj.layer);
&&&&&&&&&&&&}
layerMask参数:&&
Raycast (ray :
Ray, out hitInfo : RaycastHit, distance : float = Mathf.Infinity,
layerMask : int = kDefaultRaycastLayers)
其实很简单:1 &&
10&&打开第10的层。
~(1 && 10)
打开除了第10之外的层。
打开所有的层。
(1 && 10) |
(1 && 8) 打开第10和第8的层。
列子如下:using&UnityEngine;
using&System.Collections;
public&class&LayerMaskTest&:&MonoBehaviour&{
&&&&//&Use&this&for&initialization
&&&&void&Start&()&
&&&&&&&&mainCrma&=&Camera.main;
&&&&&&&&mask&=&1&&(&LayerMask.NameToLayer("cube"));//实例化mask到cube这个自定义的层级之上。
&&&&//private&LayerMask&mask&1&&10;
&&&&private&LayerMask&mask;
&&&&private&Camera&mainCrma;
&&&&private&RaycastHit&objhit;
&&&&private&Ray&_ray;
&&&&void&Update&()&
&&&&&&&&if&(Input.GetMouseButtonDown(0))&
&&&&&&&&&&&&_ray=mainCrma.ScreenPointToRay(Input.mousePosition);//从摄像机发出一条射线,到点击的坐标
&&&&&&&&&&&&Debug.DrawLine(_ray.origin,objhit.point,Color.red,2);//划出射线,只有在scene视图中才能看到
&&&&&&&&&&&&if&(Physics.Raycast&(_ray,out&objhit,&100,&mask.value))
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&GameObject&gameObj&=&objhit.collider.gameObject;
&&&&&&&&&&&&&&&&Debug.Log("Hit&objname:"+gameObj.name+"--Hit&objlayerName:"+LayerMask.LayerToName&(10));
&&&&&&&&&&&&}
&&&&&&&&&&&&
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。unity3d游戏开发之刚体和碰撞检测_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
unity3d游戏开发之刚体和碰撞检测
上传于|0|0|文档简介
&&unity3d游戏开发之刚体和碰撞检测
阅读已结束,如果下载本文需要使用0下载券
想免费下载更多文档?
定制HR最喜欢的简历
下载文档到电脑,查找使用更方便
还剩1页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢

我要回帖

更多关于 unity2d碰撞检测 的文章

 

随机推荐