private void UnbindBone(HumanSegment segment, Transform bone) { if (bone != null) { bone.SetParent(base.transform, worldPositionStays: false); } }
private void RegisterBody(HumanSegment segment, HumanSegment relativeTo, bool pos, bool rot, int precision = 0) { NetIdentity netIdentity = segment.rigidbody.gameObject.AddComponent<NetIdentity>(); netIdentity.sceneId = (uint)nextIdentityId++; NetBody netBody = segment.rigidbody.gameObject.AddComponent<NetBody>(); netBody.despawnHeight = float.NegativeInfinity; netBody.disableSleep = true; netBody.syncPosition = (pos ? ((relativeTo == null) ? NetBodySyncPosition.Absolute : NetBodySyncPosition.Relative) : NetBodySyncPosition.None); netBody.syncRotation = (rot ? ((relativeTo == null) ? NetBodySyncRotation.Absolute : NetBodySyncRotation.Relative) : NetBodySyncRotation.None); netBody.relativeTo = relativeTo?.transform; netBody.rotPrecision = precision; netBody.posPrecision = precision; if (netBody.syncPosition == NetBodySyncPosition.Absolute) { netBody.posRangeOverride = 4000f; netBody.posPrecision += 2; } if (relativeTo != null) { netBody.posRangeOverride = 2f; netBody.posPrecision -= 2; } AddIdentity(netIdentity); netBody.Start(); if (NetGame.isClient && pos) { segment.rigidbody.gameObject.SetActive(value: false); } }
// Token: 0x06002C06 RID: 11270 RVA: 0x0012E920 File Offset: 0x0012CB20 public void TouchTask(HumanSegment mem, Human human) { if ((double)(this.killer.human.ragdoll.partLeftHand.transform.position - mem.transform.position).sqrMagnitude < 0.2 || (double)(this.killer.human.ragdoll.partRightHand.transform.position - mem.transform.position).sqrMagnitude < 0.2) { human.killerGameVo.taskIsYes = true; this.peopleList.Remove(this.killerTarget); this.Msg_Pertinence(this.killer.host, "<size=25>任务完成</size>", ""); } }
public void BindBall(Transform ballTransform) { partBall = BindSegmanet(ballTransform); SpringJoint component = partBall.rigidbody.GetComponent <SpringJoint>(); component.autoConfigureConnectedAnchor = false; component.connectedAnchor = partHips.transform.InverseTransformPoint(base.transform.position + Vector3.up * ((partBall.collider as SphereCollider).radius + component.maxDistance)); component.connectedBody = partHips.rigidbody; }
private void BindBone(HumanSegment segment, Transform bone) { if (bone != null) { Matrix4x4 matrix4x = segment.bindPose * bone.localToWorldMatrix; bone.SetParent(segment.transform, worldPositionStays: false); bone.localPosition = matrix4x.GetColumn(3); bone.localRotation = Quaternion.LookRotation(matrix4x.GetColumn(2), matrix4x.GetColumn(1)); } }
private float GetForceRelief(Human human, HumanSegment hand) { if (!hand.sensor.IsGrabbed(base.gameObject)) { return(0f); } Vector3 normalized = base.transform.TransformVector(breakNormal).normalized; float b = Mathf.InverseLerp(0.5f, 0.9f, Vector3.Dot(normalized, human.controls.walkDirection)); return(Mathf.Max(0f, b)); }
private HumanSegment BindSegmanet(Transform transform) { HumanSegment humanSegment = new HumanSegment(); humanSegment.transform = transform; humanSegment.collider = humanSegment.transform.GetComponent <Collider>(); humanSegment.rigidbody = humanSegment.transform.GetComponent <Rigidbody>(); humanSegment.startupRotation = humanSegment.transform.localRotation; humanSegment.sensor = humanSegment.transform.GetComponent <CollisionSensor>(); humanSegment.bindPose = humanSegment.transform.worldToLocalMatrix * base.transform.localToWorldMatrix; return(humanSegment); }
private void UnblockArmBehindTheBack(HumanSegment hand, float direction) { Vector3 center = ragdoll.partHead.collider.bounds.center; Vector3 center2 = hand.collider.bounds.center; Vector3 vector = ragdoll.partChest.transform.InverseTransformVector(center2 - center); float num = Mathf.InverseLerp(0f, -0.1f, vector.z) * Mathf.InverseLerp(0.1f, -0.1f, vector.x * direction) * Mathf.InverseLerp(-0.3f, -0.1f, vector.y); if (num > 0f) { ragdoll.partHead.rigidbody.SafeAddForce((0f - direction) * num * ragdoll.partChest.transform.right * 200f); hand.rigidbody.SafeAddForce(direction * num * ragdoll.partChest.transform.right * 200f); } }
public static void AlignLook(HumanSegment segment, Quaternion targetRotation, float accelerationSpring, float damping) { (targetRotation * Quaternion.Inverse(segment.transform.rotation)).ToAngleAxis(out float angle, out Vector3 axis); if (angle > 180f) { angle -= 360f; } if (angle < -180f) { angle += 360f; } segment.rigidbody.SafeAddTorque(axis * angle * accelerationSpring - segment.rigidbody.angularVelocity * damping, ForceMode.Acceleration); }
private void AddAntistretch(HumanSegment seg1, HumanSegment seg2) { ConfigurableJoint configurableJoint = seg1.rigidbody.gameObject.AddComponent <ConfigurableJoint>(); ConfigurableJointMotion configurableJointMotion2 = configurableJoint.zMotion = ConfigurableJointMotion.Limited; configurableJointMotion2 = (configurableJoint.xMotion = (configurableJoint.yMotion = configurableJointMotion2)); configurableJoint.linearLimit = new SoftJointLimit { limit = (seg1.transform.position - seg2.transform.position).magnitude }; configurableJoint.autoConfigureConnectedAnchor = false; configurableJoint.anchor = Vector3.zero; configurableJoint.connectedBody = seg2.rigidbody; configurableJoint.connectedAnchor = Vector3.zero; }
private void CollectSegments() { Dictionary <string, Transform> dictionary = new Dictionary <string, Transform>(); Transform[] componentsInChildren = GetComponentsInChildren <Transform>(); for (int i = 0; i < componentsInChildren.Length; i++) { dictionary[componentsInChildren[i].name.ToLower()] = componentsInChildren[i]; } partHead = FindSegment(dictionary, "head"); partChest = FindSegment(dictionary, "chest"); partWaist = FindSegment(dictionary, "waist"); partHips = FindSegment(dictionary, "hips"); partLeftArm = FindSegment(dictionary, "leftArm"); partLeftForearm = FindSegment(dictionary, "leftForearm"); partLeftHand = FindSegment(dictionary, "leftHand"); partLeftThigh = FindSegment(dictionary, "leftThigh"); partLeftLeg = FindSegment(dictionary, "leftLeg"); partLeftFoot = FindSegment(dictionary, "leftFoot"); partRightArm = FindSegment(dictionary, "rightArm"); partRightForearm = FindSegment(dictionary, "rightForearm"); partRightHand = FindSegment(dictionary, "rightHand"); partRightThigh = FindSegment(dictionary, "rightThigh"); partRightLeg = FindSegment(dictionary, "rightLeg"); partRightFoot = FindSegment(dictionary, "rightFoot"); SetupHeadComponents(partHead); SetupBodyComponents(partChest); SetupBodyComponents(partWaist); SetupBodyComponents(partHips); SetupLimbComponents(partLeftArm); SetupLimbComponents(partLeftForearm); SetupLimbComponents(partLeftThigh); SetupLimbComponents(partLeftLeg); SetupLimbComponents(partRightArm); SetupLimbComponents(partRightForearm); SetupLimbComponents(partRightThigh); SetupLimbComponents(partRightLeg); SetupFootComponents(partLeftFoot); SetupFootComponents(partRightFoot); SetupHandComponents(partLeftHand); SetupHandComponents(partRightHand); partLeftHand.sensor.otherSide = partRightHand.sensor; partRightHand.sensor.otherSide = partLeftHand.sensor; AddAntistretch(partLeftHand, partChest); AddAntistretch(partRightHand, partChest); AddAntistretch(partLeftFoot, partHips); AddAntistretch(partRightFoot, partHips); }
private Vector3 AnimateLeg(HumanSegment thigh, HumanSegment leg, HumanSegment foot, float phase, Vector3 torsoFeedback, float tonus) { tonus *= 20f; phase -= Mathf.Floor(phase); if (phase < 0.2f) { HumanMotion2.AlignToVector(thigh, thigh.transform.up, human.controls.walkDirection + Vector3.down, 3f * tonus); HumanMotion2.AlignToVector(leg, thigh.transform.up, -human.controls.walkDirection - Vector3.up, tonus); Vector3 vector = Vector3.up * 20f; foot.rigidbody.SafeAddForce(vector); return(-vector); } if (phase < 0.5f) { HumanMotion2.AlignToVector(thigh, thigh.transform.up, human.controls.walkDirection, 2f * tonus); HumanMotion2.AlignToVector(leg, thigh.transform.up, human.controls.walkDirection, 3f * tonus); } else { if (phase < 0.7f) { Vector3 vector2 = torsoFeedback * 0.2f; foot.rigidbody.SafeAddForce(vector2); HumanMotion2.AlignToVector(thigh, thigh.transform.up, human.controls.walkDirection + Vector3.down, tonus); HumanMotion2.AlignToVector(leg, thigh.transform.up, Vector3.down, tonus); return(-vector2); } if (phase < 0.9f) { Vector3 vector3 = torsoFeedback * 0.2f; foot.rigidbody.SafeAddForce(vector3); HumanMotion2.AlignToVector(thigh, thigh.transform.up, -human.controls.walkDirection + Vector3.down, tonus); HumanMotion2.AlignToVector(leg, thigh.transform.up, -human.controls.walkDirection + Vector3.down, tonus); return(-vector3); } HumanMotion2.AlignToVector(thigh, thigh.transform.up, -human.controls.walkDirection + Vector3.down, tonus); HumanMotion2.AlignToVector(leg, thigh.transform.up, -human.controls.walkDirection, tonus); } return(Vector3.zero); }
public void FixedUpdate() { Human h = GetLocalHuman(); if (fly && h != null) { flyVelTgt = (h.controls.walkSpeed > 0) ? h.controls.walkDirection : Vector3.zero; if (Input.GetKey(KeyCode.Space)) { flyVelTgt += Vector3.up; } if (Input.GetKey(KeyCode.LeftShift)) { flyVelTgt += Vector3.down; } flyVelTgt *= flySpeed; Vector3 flyVelCurr = h.ragdoll.partChest.rigidbody.velocity; Vector3 impulse = Vector3.MoveTowards(Vector3.zero, flyVelTgt - flyVelCurr, flyMaxAcc * Time.fixedDeltaTime); foreach (Rigidbody r in h.rigidbodies) { r.SafeAddForce(impulse, ForceMode.VelocityChange); } HumanSegment[] hands = new HumanSegment[2] { h.ragdoll.partLeftHand, h.ragdoll.partRightHand }; Rigidbody bodyPrv = null; foreach (HumanSegment hand in hands) { if (hand.sensor.grab && hand.sensor.grabBody && !hand.sensor.grabBody.isKinematic && bodyPrv != hand.sensor.grabBody) { hand.sensor.grabBody.SafeAddForceAtPosition(impulse, hand.transform.position, ForceMode.VelocityChange); bodyPrv = hand.sensor.grabBody; } } } }
private void AnimateHand(HumanSegment arm, HumanSegment forearm, HumanSegment hand, float phase, float tonus, bool right) { tonus *= 50f * human.controls.walkSpeed; phase -= Mathf.Floor(phase); Vector3 a = Quaternion.Euler(0f, human.controls.targetYawAngle, 0f) * Vector3.forward; Vector3 vector = Quaternion.Euler(0f, human.controls.targetYawAngle, 0f) * Vector3.right; if (!right) { vector = -vector; } if (phase < 0.5f) { HumanMotion2.AlignToVector(arm, arm.transform.up, Vector3.down + vector / 2f, 3f * tonus); HumanMotion2.AlignToVector(forearm, forearm.transform.up, a / 2f - vector, 3f * tonus); } else { HumanMotion2.AlignToVector(arm, arm.transform.up, -a + vector / 2f, 3f * tonus); HumanMotion2.AlignToVector(forearm, forearm.transform.up, a + Vector3.down, 3f * tonus); } }
public static void AlignToVector(HumanSegment part, Vector3 alignmentVector, Vector3 targetVector, float spring) { AlignToVector(part.rigidbody, alignmentVector, targetVector, spring); }
private void LiftBody(HumanSegment hand, Rigidbody body) { if (human.GetComponent <GroundManager>().IsStanding(body.gameObject) || body.tag == "NoLift") { return; } float num = 0.5f + 0.5f * Mathf.InverseLerp(0f, 100f, body.mass); Vector3 vector = (human.targetLiftDirection.ZeroY() * maxPushForce).SetY(Mathf.Max(0f, human.targetLiftDirection.y) * maxLiftForce); float magnitude = (hand.transform.position - body.worldCenterOfMass).magnitude; float num2 = num; float num3 = 1f; float d = 1f; Carryable component = body.GetComponent <Carryable>(); if (component != null) { num2 *= component.liftForceMultiplier; num3 = component.forceHalfDistance; d = component.damping; if (num3 <= 0f) { throw new InvalidOperationException("halfdistance cant be 0 or less!"); } } float num4 = num3 / (num3 + magnitude); vector *= num2; vector *= num4; body.SafeAddForce(vector); hand.rigidbody.SafeAddForce(-vector * 0.5f); ragdoll.partChest.rigidbody.SafeAddForce(-vector * 0.5f); body.SafeAddTorque(-body.angularVelocity * liftDamp * d, ForceMode.Acceleration); body.SafeAddTorque(-body.angularVelocity.normalized * body.angularVelocity.sqrMagnitude * liftDampSqr * d, ForceMode.Acceleration); if (!(component != null) || component.aiming == CarryableAiming.None) { return; } Vector3 vector2 = human.targetLiftDirection; if (component.limitAlignToHorizontal) { vector2.y = 0f; vector2.Normalize(); } Vector3 vector3 = (component.aiming != CarryableAiming.ForwardAxis) ? (body.worldCenterOfMass - hand.transform.position).normalized : body.transform.forward; float aimSpring = component.aimSpring; float num5 = (!(component.aimTorque < float.PositiveInfinity)) ? aimSpring : component.aimTorque; if (!component.alwaysForward) { float num6 = Vector3.Dot(vector3, vector2); if (num6 < 0f) { vector2 = -vector2; num6 = 0f - num6; } num5 *= Mathf.Pow(num6, component.aimAnglePower); } else { float num7 = Vector3.Dot(vector3, vector2); num7 = 0.5f + num7 / 2f; num5 *= Mathf.Pow(num7, component.aimAnglePower); } if (component.aimDistPower != 0f) { num5 *= Mathf.Pow((body.worldCenterOfMass - hand.transform.position).magnitude, component.aimDistPower); } HumanMotion2.AlignToVector(body, vector3, vector2, aimSpring, num5); }
private void PlaceHand(HumanSegment arm, HumanSegment hand, Vector3 worldPos, bool active, bool grabbed, Rigidbody grabbedBody) { if (!active) { return; } Rigidbody rigidbody = hand.rigidbody; Vector3 worldCenterOfMass = rigidbody.worldCenterOfMass; Vector3 offset = worldPos - worldCenterOfMass; Vector3 vector = new Vector3(0f, offset.y, 0f); Vector3 velocity = rigidbody.velocity - ragdoll.partBall.rigidbody.velocity; float num = armMass; float num2 = maxForce; if (grabbed) { if (grabbedBody != null) { num += Mathf.Clamp(grabbedBody.mass / 2f, 0f, bodyMass); num2 = Mathf.Lerp(grabMaxForce, climbMaxForce, (human.controls.targetPitchAngle - 50f) / 30f); } else { num += bodyMass; num2 = Mathf.Lerp(grabMaxForce, climbMaxForce, (human.controls.targetPitchAngle - 50f) / 30f); } } float maxAcceleration = num2 / num; Vector3 a = ConstantAccelerationControl.Solve(offset, velocity, maxAcceleration, 0.1f); int num3 = 600; Vector3 vector2 = a * num + Vector3.up * gravityForce; if (human.grabbedByHuman != null && human.grabbedByHuman.state == HumanState.Climb) { vector2 *= 1.7f; num3 *= 2; } if (!grabbed) { rigidbody.SafeAddForce(vector2); ragdoll.partHips.rigidbody.SafeAddForce(-vector2); return; } Vector3 normalized = human.targetDirection.ZeroY().normalized; Vector3 b = Mathf.Min(0f, Vector3.Dot(normalized, vector2)) * normalized; Vector3 a2 = vector2 - b; Vector3 a3 = vector2.SetX(0f).SetZ(0f); Vector3 b2 = -vector2 * 0.25f; Vector3 b3 = -vector2 * 0.75f; Vector3 a4 = -vector2 * 0.1f - a3 * 0.5f - a2 * 0.25f; Vector3 a5 = -a3 * 0.2f - a2 * 0.4f; if (grabbedBody != null) { Carryable component = grabbedBody.GetComponent <Carryable>(); if (component != null) { b2 *= component.handForceMultiplier; b3 *= component.handForceMultiplier; } } float d = (human.state != HumanState.Climb) ? 1f : Mathf.Clamp01((human.controls.targetPitchAngle - 10f) / 60f); Vector3 vector3 = Vector3.Lerp(a4, b2, offset.y + 0.5f) * d; Vector3 vector4 = Vector3.Lerp(a5, b3, offset.y + 0.5f) * d; float num4 = Mathf.Abs(vector3.y + vector4.y); if (num4 > (float)num3) { vector3 *= (float)num3 / num4; vector4 *= (float)num3 / num4; } ragdoll.partChest.rigidbody.SafeAddForce(vector3); ragdoll.partBall.rigidbody.SafeAddForce(vector4); rigidbody.SafeAddForce(-vector3 - vector4); }
private void ProcessHand(ScanMem mem, HumanSegment arm, HumanSegment forearm, HumanSegment hand, Vector3 worldPos, float extend, bool grab, float animationPhase, bool right) { double num = 0.1 + (double)(0.14f * Mathf.Abs(human.controls.targetPitchAngle - mem.grabAngle) / 80f); double num2 = num * 2.0; if (CheatCodes.climbCheat) { num2 = (num /= 4.0); } if (grab && !hand.sensor.grab) { if ((double)mem.grabTime > num) { mem.pos = arm.transform.position; } else { grab = false; } } if (hand.sensor.grab && !grab) { mem.grabTime = 0f; mem.grabAngle = human.controls.targetPitchAngle; } else { mem.grabTime += Time.fixedDeltaTime; } hand.sensor.grab = ((double)mem.grabTime > num2 && grab); if (extend > 0.2f) { bool flag = false; hand.sensor.targetPosition = worldPos; Vector3 vector = worldPos; mem.shoulder = arm.transform.position; mem.hand = hand.transform.position; if (hand.sensor.grabJoint == null) { worldPos = FindTarget(mem, worldPos, out hand.sensor.grabFilter); } PlaceHand(arm, hand, worldPos, active: true, hand.sensor.grabJoint != null, hand.sensor.grabBody); if (hand.sensor.grabBody != null) { LiftBody(hand, hand.sensor.grabBody); } hand.sensor.grabPosition = worldPos; } else { hand.sensor.grabFilter = null; if (human.state == HumanState.Walk) { AnimateHand(arm, forearm, hand, animationPhase, 1f, right); } else if (human.state == HumanState.FreeFall) { Vector3 targetDirection = human.targetDirection; targetDirection.y = 0f; HumanMotion2.AlignToVector(arm, arm.transform.up, -targetDirection, 2f); HumanMotion2.AlignToVector(forearm, forearm.transform.up, targetDirection, 2f); } else { Vector3 targetDirection2 = human.targetDirection; targetDirection2.y = 0f; HumanMotion2.AlignToVector(arm, arm.transform.up, -targetDirection2, 20f); HumanMotion2.AlignToVector(forearm, forearm.transform.up, targetDirection2, 20f); } } }
private void ProcessHand(HandMuscles.ScanMem mem, HumanSegment arm, HumanSegment forearm, HumanSegment hand, Vector3 worldPos, float extend, bool grab, float animationPhase, bool right) { double num = 0.1 + (double)(0.14f * Mathf.Abs(this.human.controls.targetPitchAngle - mem.grabAngle) / 80f); double num2 = num * 2.0; if (CheatCodes.climbCheat) { num = (num2 = num / 4.0); } if (grab && !hand.sensor.grab) { if ((double)mem.grabTime > num) { mem.pos = arm.transform.position; } else { grab = false; } } if (hand.sensor.grab && !grab) { mem.grabTime = 0f; mem.grabAngle = this.human.controls.targetPitchAngle; } else { mem.grabTime += Time.fixedDeltaTime; } hand.sensor.grab = ((double)mem.grabTime > num2 && grab); if (this.human.mod_vo.isBoxing && extend < 0.2f) { hand.sensor.targetPosition = worldPos; mem.shoulder = arm.transform.position; mem.hand = hand.transform.position; this.maxPushForce *= 3f; if (hand.sensor.grabJoint == null) { worldPos = this.FindTarget(mem, worldPos, out hand.sensor.grabFilter); } this.PlaceHand(arm, hand, worldPos, true, hand.sensor.grabJoint != null, hand.sensor.grabBody); if (hand.sensor.grabBody != null) { this.LiftBody(hand, hand.sensor.grabBody); } hand.sensor.grabPosition = worldPos; return; } if (extend > 0.2f) { hand.sensor.targetPosition = worldPos; mem.shoulder = arm.transform.position; mem.hand = hand.transform.position; if (hand.sensor.grabJoint == null) { worldPos = this.FindTarget(mem, worldPos, out hand.sensor.grabFilter); } this.PlaceHand(arm, hand, worldPos, true, hand.sensor.grabJoint != null, hand.sensor.grabBody); if (hand.sensor.grabBody != null) { this.LiftBody(hand, hand.sensor.grabBody); } hand.sensor.grabPosition = worldPos; return; } hand.sensor.grabFilter = null; if (this.human.state == HumanState.Walk) { this.AnimateHand(arm, forearm, hand, animationPhase, 1f, right); return; } if (this.human.state == HumanState.FreeFall) { Vector3 targetDirection = this.human.targetDirection; targetDirection.y = 0f; HumanMotion2.AlignToVector(arm, arm.transform.up, -targetDirection, 2f); HumanMotion2.AlignToVector(forearm, forearm.transform.up, targetDirection, 2f); return; } if (this.human.mod_vo.isBoxing) { return; } Vector3 targetDirection2 = this.human.targetDirection; targetDirection2.y = 0f; HumanMotion2.AlignToVector(arm, arm.transform.up, -targetDirection2, 20f); HumanMotion2.AlignToVector(forearm, forearm.transform.up, targetDirection2, 20f); }
private void SetupFootComponents(HumanSegment part) { part.sensor = part.transform.gameObject.AddComponent <CollisionSensor>(); part.transform.gameObject.AddComponent <FootCollisionAudioSensor>(); part.sensor.groundCheck = true; }
private void SetupHandComponents(HumanSegment part) { part.sensor = part.transform.gameObject.AddComponent <CollisionSensor>(); part.transform.gameObject.AddComponent <CollisionAudioSensor>(); }
private void SetupBodyComponents(HumanSegment part) { part.sensor = part.transform.gameObject.AddComponent <CollisionSensor>(); part.transform.gameObject.AddComponent <CollisionAudioSensor>(); part.sensor.knockdown = 1f; }