赞
踩
这里使用的是Obi Rope 6.4
使用Chains默认的Demo场景
如果播放后,Target物体掉落可将其重力关闭,锁住坐标与旋转变换。
脚本文件取自:
http://obi.virtualmethodstudio.com/manual/6.3/scriptingcollisions.html
http://obi.virtualmethodstudio.com/manual/6.3/scriptingropes.html
using UnityEngine; using Obi; [RequireComponent(typeof(ObiSolver))] public class CollisionEventHandler : MonoBehaviour { ObiSolver solver; public ObiRope rope; private bool isTear = true; void Awake() { solver = GetComponent<ObiSolver>(); } void OnEnable() { solver.OnCollision += Solver_OnCollision; } void OnDisable() { solver.OnCollision -= Solver_OnCollision; } void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e) { var world = ObiColliderWorld.GetInstance(); // just iterate over all contacts in the current frame: foreach (Oni.Contact contact in e.contacts) { // if this one is an actual collision: if (contact.distance < 0.01) { ObiColliderBase col = world.colliderHandles[contact.bodyB].owner; if (col != null) { // do something with the collider. // print(col.gameObject.name); int particleIndex = solver.simplices[contact.bodyA]; print(particleIndex); if(isTear) { isTear = false; rope.Tear(rope.elements[particleIndex]); rope.RebuildConstraintsFromElements(); } } } } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。