remove additionally added colliders from ragdoll (jaw, neck box)

This commit is contained in:
in0finite 2021-01-04 22:08:51 +01:00
parent d6d5d660cf
commit 9a224c0eca
2 changed files with 22 additions and 6 deletions

View file

@ -5,6 +5,7 @@
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
#pragma warning disable 649
@ -45,7 +46,7 @@ namespace SanAndreasUnity
Vector3 worldForward = Vector3.forward;
public bool flipForward = false;
class BoneInfo
public class BoneInfo
{
public string name;
@ -68,9 +69,14 @@ namespace SanAndreasUnity
public float summedMass;// The mass of this and all children bodies
}
ArrayList bones;
List<BoneInfo> bones;
public List<BoneInfo> Bones => bones;
BoneInfo rootBone;
public List<Collider> AdditionalColliders = new List<Collider>();
string CheckConsistency()
{
PrepareBones();
@ -139,7 +145,7 @@ namespace SanAndreasUnity
worldForward = pelvis.TransformDirection(forward);
}
bones = new ArrayList();
bones = new List<BoneInfo>();
rootBone = new BoneInfo();
rootBone.name = "Pelvis";
@ -519,6 +525,9 @@ namespace SanAndreasUnity
newBox.size = new Vector3(radius * 0.65f, 0.75f * breastBox.size.y, 0.5f * breastBox.size.z);
newBox.center = breastBox.center + Vector3.right * (breastBox.size.x * 0.5f + newBox.size.x * 0.5f);
AdditionalColliders.Add(jawSphere);
AdditionalColliders.Add(newBox);
}
}
}

View file

@ -387,17 +387,24 @@ namespace SanAndreasUnity.Behaviours
if (null == m_ragdollBuilder)
return null;
if (null == this.UnnamedFrame)
if (null == this.RootFrame)
return null;
var ragdollTransform = this.RootFrame.transform;
// remove colliders which are not part of ragdoll
foreach (var c in m_ragdollBuilder.AdditionalColliders)
{
Debug.Log($"removing collider on {c.name} because it is not one of ragdoll bones");
Object.Destroy(c);
}
m_ragdollBuilder.BuildBodies();
m_ragdollBuilder.BuildJoints();
m_ragdollBuilder.CalculateMass();
m_ragdollBuilder = null;
var ragdollTransform = this.UnnamedFrame.transform;
ragdollTransform.SetParent(null);
foreach (var rb in ragdollTransform.GetComponentsInChildren<Rigidbody>())