protected void SendPedToRagdoll(int pedEntity, RagdollStates ragdollType) { SetPedToRagdollEvent ragdoll; EcsWorld.CreateEntityWith(out ragdoll); ragdoll.Entity = pedEntity; ragdoll.RagdollState = ragdollType; }
protected virtual void LateUpdate() { _animator.SetBool("GetUpFromBelly", false); _animator.SetBool("GetUpFromBack", false); if (CurrentState == RagdollStates.Blending) { if (Time.time <= _ragdollingEndTimestamp + _mecanimToGetUpTransitionTime) { Vector3 animatedToRagdolling = _ragdolledHipPosition - _animator.GetBoneTransform(HumanBodyBones.Hips).position; Vector3 newRootPosition = transform.position + animatedToRagdolling; RaycastHit[] hits = Physics.RaycastAll(new Ray(newRootPosition, Vector3.down)); newRootPosition.y = 0; foreach (RaycastHit hit in hits) { if (!hit.transform.IsChildOf(transform)) { newRootPosition.y = Mathf.Max(newRootPosition.y, hit.point.y); } } transform.position = newRootPosition; Vector3 ragdollingDirection = _ragdolledHeadPosition - _ragdolledFeetPosition; ragdollingDirection.y = 0; Vector3 meanFeetPosition = 0.5f * (_animator.GetBoneTransform(HumanBodyBones.LeftFoot).position + _animator.GetBoneTransform(HumanBodyBones.RightFoot).position); Vector3 animatedDirection = _animator.GetBoneTransform(HumanBodyBones.Head).position - meanFeetPosition; animatedDirection.y = 0; transform.rotation *= Quaternion.FromToRotation(animatedDirection.normalized, ragdollingDirection.normalized); } float ragdollBlendAmount = 1.0f - (Time.time - _ragdollingEndTimestamp - _mecanimToGetUpTransitionTime) / RagdollToMecanimBlendDuration; ragdollBlendAmount = Mathf.Clamp01(ragdollBlendAmount); foreach (RagdollBodypart bodypart in _bodyparts) { if (bodypart.BodyPartTransform != transform) { if (bodypart.BodyPartTransform == _animator.GetBoneTransform(HumanBodyBones.Hips)) { bodypart.BodyPartTransform.position = Vector3.Lerp(bodypart.BodyPartTransform.position, bodypart.StoredPosition, ragdollBlendAmount); } bodypart.BodyPartTransform.rotation = Quaternion.Slerp(bodypart.BodyPartTransform.rotation, bodypart.StoredRotation, ragdollBlendAmount); } } if (ragdollBlendAmount == 0) { CurrentState = RagdollStates.Animated; return; } } }