Unity3d 刚体与障碍物解疑
Unity3d 障碍物:主角绑定Collider组件,Is Trigger不打勾,其他默认。主角绑定Rigidbody组件,Use Gravity打勾,Is Kinematic不打勾,Constraints是当前力不作用于,Freeze Rotation x,y,z打勾。
问题:gameobject的scale缩放了0.01倍(其他倍另测),发现了主角刚体无论怎么移动或者设置属性,都会穿透障碍物。
解决:需要把FBX资源的大小规格设置成unity3d场景中的等比例规格(可以随意建个Plane和Cube参考大小),这样刚体就不会穿透障碍物了。
Unity3d按键事件(1):
if (Input.GetKey(KeyCode.A))
{
if (active == ACTIVE.NONE)
{
transform.Rotate(new Vector3(0, -1, 0));
}
}
else if (Input.GetKey(KeyCode.D))
{
if (active == ACTIVE.NONE)
{
transform.Rotate(new Vector3(0, 1, 0));
}
}
if (Input.GetKey(KeyCode.W))
{
if (active == ACTIVE.NONE)
{
anim.SetFloat("Speed", 0.11f);
gameObject.transform.Translate(Vector3.left * speed * Time.deltaTime);
}
}
if (Input.GetKeyDown(KeyCode.Space))
{
if (active == ACTIVE.NONE)
{
animation.Play("jump");
active = ACTIVE.JUMP;
}
}
if (Input.GetKeyUp(KeyCode.J))
{
if (active == ACTIVE.NONE)
{
animation.Play("attack1");
active = ACTIVE.ATTACK1;
}
}
if (Input.GetKeyUp(KeyCode.K))
{
if (active == ACTIVE.NONE)
{
animation.Play("attack2");
active = ACTIVE.ATTACK2;
}
}
if (Input.GetKeyUp(KeyCode.U))
{
if (active == ACTIVE.NONE)
{
animation.Play("attack3");
active = ACTIVE.ATTACK3;
}
}
if (Input.GetKeyUp(KeyCode.I))
{
if (active == ACTIVE.NONE)
{
animation.Play("attack4");
active = ACTIVE.ATTACK4;
}
}
Unity3d 鼠标点击射线到世界:
if (Input.GetMouseButtonDown(0))
{
animation.Play("move");
Ray ray = cameraObj.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
target = hit.point;
// gameObject.transform.LookAt(ver);
gameObject.transform.LookAt(target);
// animation.m
// gameObject.transform.Rotate(0, 90, 0);
// isMove = true;
Debug.Log("point------" + target);
Debug.Log("what is this------" + hit.transform.name);
}
}
转载请注明:少狼 – 敬畏知识的顽皮狗 » Unity3d 刚体与障碍物解疑
还没有人抢沙发呢~