public BraidChain(IComplexHuman human, params Transform[] nodes) : base(BodyPart.Braid) { _human = human; _nodes = nodes ?? throw new ArgumentException("No braid nodes found"); _tempPositions = new Vector3[_nodes.Length + 2]; // 1 x each node + 1 root + 1 handler _tempFw = new Vector3[_nodes.Length + 1]; // for each temp position except root _joinLengths = new float[_nodes.Length + 1]; _joinLengths[0] = _human.Head.position.DistanceTo(_nodes[0].position); for (var i = 1; i < _nodes.Length; ++i) { var last = _nodes[i - 1]; var curr = _nodes[i]; _joinLengths[i] = vDist(last.position, curr.position); } const float LastLen = 0.1f; _joinLengths[_joinLengths.Length - 1] = LastLen; var lastNode = nodes[nodes.Length - 1]; // hair6 _handle = CreateHandle(_human.Head.Holder, BodyPart.Braid, false, lastNode.position + lastNode.forward.By(LastLen), human.dn, human.bk); _iniRootPositions = new Vector3[_nodes.Length + 1]; // for each position except root for (var i = 0; i < _nodes.Length; ++i) { _iniRootPositions[i] = _nodes[i].position.AsLocalPoint(_human.Head); } _iniRootPositions[_iniRootPositions.Length - 1] = _handle.position.AsLocalPoint(_human.Head); _headToHandleDist = _handle.position.DistanceTo(_human.Head.position); _handleIniLocPos = _handle.localPosition; _pendulum = new PendulumPhysicsAgent( stiffness: 0.005, mass: 0.50, damping: 0.85, gravity: 0); }
internal SoftBodyJiggleAgent(ISoftBodyConfig config) { _ppa = new PendulumPhysicsAgent(config.Stiffness, config.Mass, config.Damping, config.Gravity); _cfg = config; _relStaticTarget = (_cfg.Bone.position + _cfg.Bone.forward * (float)_cfg.RelTargetAt) .AsLocalPoint(_cfg.Bone.parent); _relIniPos = _cfg.Bone.position.AsLocalPoint(_cfg.Bone.parent); _relIniFw = _cfg.Bone.forward.AsLocalDir(_cfg.Bone.parent); _relIniUp = _cfg.Bone.up.AsLocalDir(_cfg.Bone.parent); }
void Start() { // fun.setTimeScale(0.2); _soft = GameObject.CreatePrimitive(PrimitiveType.Sphere).transform .SetScale(1.2).SetColor(0xFF0000FF).SetHideFlags(HideFlags.HideInHierarchy); _rigid = GameObject.CreatePrimitive(PrimitiveType.Cube).transform .SetScale(1).SetColor(0x0000FFFF).SetPosition(-2.5, 0, 0); _ppa = new PendulumPhysicsAgent(); _log = GameObject.Find("LogText").GetComponent <Text>(); }