大佬教程收集整理的这篇文章主要介绍了如何使 Physics2D.IgnoreLayerCollision 仅忽略物理硬碰撞而不触发碰撞?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我刚刚发现了如何忽略冲突,这真的很有帮助。我想要它,因为我想要我的游戏中的一些宝藏既有物理硬碰撞器,也有我的玩家触摸它时的触发器。我不希望我的玩家与宝藏发生物理碰撞,但我确实希望我的宝藏在地面上发生物理碰撞而不是掉下来。
不幸的是,当我使用 Physics2D.IgnoreLayerCollision
时,它也忽略了我在玩家走过宝藏捡起它时使用的触发器碰撞器。我想启用触发碰撞器,禁用物理硬碰撞器。
这是我的代码:
public class collIDerTreasureScript : MonoBehavIoUr
{
public RigIDbody2D rb;
public float jumpforce;
public float speed;
public LayerMask playerlayer; // 8
public LayerMask treasurelayer; // 9
// Start is called before the first frame update
voID Start()
{
Physics2D.IgnoreLayerCollision(8,9,truE);
Physics2D.IgnoreLayerCollision(9,8,truE);
rb = GetComponent<RigIDbody2D>();
rb.AddForce(Vector2.up * jumpforce * Time.deltaTime,ForceMode2D.ImpulsE);
}
这是另一个捡到宝物的脚本
public class GenericTreasureScript : MonoBehavIoUr
{
public float rotatespeed;
private Player playerscript;
public int treasurevalue;
public transform movetoWARDsposition;
public float speed;
public bool touched;
// public CircleCollIDer2D heavycollIDer;
// Start is called before the first frame update
voID Start()
{
movetoWARDsposition = GameObject.Find("scorepositionupdated").transform;
touched = false;
playerscript = FindobjectOfType<Player>();
//rotatespeed = Random.Range(140,155.3f);
speed = Random.Range(18,22);
}
// update is called once per frame
voID update()
{
if (touched == truE)
{
transform.position = Vector2.MovetoWARDs(transform.position,movetoWARDsposition.position,speed * Time.deltaTimE);
}
if (Vector2.distance(transform.position,movetoWARDsposition.position) < .2f)
{
destroy();
}
}
private voID OntriggerEnter2D(CollIDer2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
playerscript.score += treasurevalue;
touched = true;
StartCoroutIne("destroyBACkup");
}
}
我不希望我的玩家与宝藏发生身体碰撞,但我 确实希望我的宝物在地面上发生物理碰撞而不是掉落 通过
如果你想将物理碰撞器和触发碰撞器分开,仍然在玩家接触时触发但不引起碰撞。
您可以:
RigidBody2D
,被触发的对象不需要RigidBody2D
,只有在您的情况下玩家才会需要并移除物理对撞机RigidBody2D
但将 gravityScale
设置为 0 并移除物理碰撞器 python test.py \
--path_input_dir gs://somepath \
--dataset somename \
--mp3d_dir gs://somepath \
--file_identifier somEID \
--output_file gs://some/other/path \
--num_instructions 1 \
--region us-east1 \
--runner DataflowRunner \
--project someproject-id \
--temp_LOCATIOn gs://someloc
,然后仅禁用该层与玩家之间的碰撞,而不是两个碰撞器都驻留在其上的层立>
示例 3:
"treasurephysicallayer"
另外设置图层通过。代码是可能的,但在 Physics2D PlayerSetTings
中设置它们要容易得多。
您可以通过代码勾选或打开您当前设置的相应碰撞。
以上是大佬教程为你收集整理的如何使 Physics2D.IgnoreLayerCollision 仅忽略物理硬碰撞而不触发碰撞?全部内容,希望文章能够帮你解决如何使 Physics2D.IgnoreLayerCollision 仅忽略物理硬碰撞而不触发碰撞?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。