/// <summary> /// Sets the body part model to be used on the creature specified. /// The model names for parts need to be in the following format: /// p /// <m/ f> /// <race letter> /// <phenotype> /// _ /// <body part> /// <model number> /// .mdl /// - nPart (CREATURE_PART_*) /// CREATURE_PART_RIGHT_FOOT /// CREATURE_PART_LEFT_FOOT /// CREATURE_PART_RIGHT_SHIN /// CREATURE_PART_LEFT_SHIN /// CREATURE_PART_RIGHT_THIGH /// CREATURE_PART_LEFT_THIGH /// CREATURE_PART_PELVIS /// CREATURE_PART_TORSO /// CREATURE_PART_BELT /// CREATURE_PART_NECK /// CREATURE_PART_RIGHT_FOREARM /// CREATURE_PART_LEFT_FOREARM /// CREATURE_PART_RIGHT_BICEP /// CREATURE_PART_LEFT_BICEP /// CREATURE_PART_RIGHT_SHOULDER /// CREATURE_PART_LEFT_SHOULDER /// CREATURE_PART_RIGHT_HAND /// CREATURE_PART_LEFT_HAND /// CREATURE_PART_HEAD /// - nModelNumber: CREATURE_MODEL_TYPE_* /// CREATURE_MODEL_TYPE_NONE /// CREATURE_MODEL_TYPE_SKIN (not for use on shoulders, pelvis or head). /// CREATURE_MODEL_TYPE_TATTOO (for body parts that support tattoos, i.e. not heads/feet/hands). /// CREATURE_MODEL_TYPE_UNDEAD (undead model only exists for the right arm parts). /// - oCreature: the creature to change the body part for. /// Note: Only part based creature appearance types are supported. /// i.e. The model types for the playable races ('P') in the appearance.2da /// </summary> public static void SetCreatureBodyPart(CreaturePart nCreaturePart, ModelType nModelNumber, uint oCreature = Core.NWScript.NWScript.OBJECT_INVALID) { Internal.NativeFunctions.StackPushObject(oCreature); Internal.NativeFunctions.StackPushInteger((int)nModelNumber); Internal.NativeFunctions.StackPushInteger((int)nCreaturePart); Internal.NativeFunctions.CallBuiltIn(793); }
/// <summary> /// returns the model number being used for the body part and creature specified /// The model number returned is for the body part when the creature is not wearing /// armor (i.e. whether or not the creature is wearing armor does not affect /// the return value). /// Note: Only works on part based creatures, which is typically restricted to /// the playable races (unless some new part based custom content has been /// added to the module). /// returns CREATURE_PART_INVALID if used on a non-creature object, /// or if the creature does not use a part based model. /// - nPart (CREATURE_PART_*) /// CREATURE_PART_RIGHT_FOOT /// CREATURE_PART_LEFT_FOOT /// CREATURE_PART_RIGHT_SHIN /// CREATURE_PART_LEFT_SHIN /// CREATURE_PART_RIGHT_THIGH /// CREATURE_PART_LEFT_THIGH /// CREATURE_PART_PELVIS /// CREATURE_PART_TORSO /// CREATURE_PART_BELT /// CREATURE_PART_NECK /// CREATURE_PART_RIGHT_FOREARM /// CREATURE_PART_LEFT_FOREARM /// CREATURE_PART_RIGHT_BICEP /// CREATURE_PART_LEFT_BICEP /// CREATURE_PART_RIGHT_SHOULDER /// CREATURE_PART_LEFT_SHOULDER /// CREATURE_PART_RIGHT_HAND /// CREATURE_PART_LEFT_HAND /// CREATURE_PART_HEAD /// </summary> public static int GetCreatureBodyPart(CreaturePart nPart, uint oCreature = OBJECT_INVALID) { Internal.NativeFunctions.StackPushObject(oCreature); Internal.NativeFunctions.StackPushInteger((int)nPart); Internal.NativeFunctions.CallBuiltIn(792); return(Internal.NativeFunctions.StackPopInteger()); }
/// <summary> /// Sets the armor color for a piece of this item. /// </summary> /// <param name="modelSlot">The model portion of the slot to assign.</param> /// <param name="colorSlot">The color portion of the slot to assign.</param> /// <param name="value">The new color to assign.</param> public void SetArmorPieceColor(CreaturePart modelSlot, ItemAppearanceArmorColor colorSlot, byte value) { const int numColors = NWScript.ITEM_APPR_ARMOR_NUM_COLORS; int index = numColors + (int)modelSlot * numColors + (int)colorSlot; SetArmorColor((ItemAppearanceArmorColor)index, value); }
/// <summary> /// Gets the armor color for a piece of this item. /// </summary> /// <param name="modelSlot">The model portion of the slot to query.</param> /// <param name="colorSlot">The color portion of the slot to query.</param> public byte GetArmorPieceColor(CreaturePart modelSlot, ItemAppearanceArmorColor colorSlot) { const int numColors = NWScript.ITEM_APPR_ARMOR_NUM_COLORS; int index = numColors + (int)modelSlot * numColors + (int)colorSlot; return(GetArmorColor((ItemAppearanceArmorColor)index)); }
/// <summary> /// Sets the body part model to be used on the creature specified. /// The model names for parts need to be in the following format: /// p /// <m/ f> /// <race letter> /// <phenotype> /// _ /// <body part> /// <model number> /// .mdl /// - nPart (CREATURE_PART_*) /// CREATURE_PART_RIGHT_FOOT /// CREATURE_PART_LEFT_FOOT /// CREATURE_PART_RIGHT_SHIN /// CREATURE_PART_LEFT_SHIN /// CREATURE_PART_RIGHT_THIGH /// CREATURE_PART_LEFT_THIGH /// CREATURE_PART_PELVIS /// CREATURE_PART_TORSO /// CREATURE_PART_BELT /// CREATURE_PART_NECK /// CREATURE_PART_RIGHT_FOREARM /// CREATURE_PART_LEFT_FOREARM /// CREATURE_PART_RIGHT_BICEP /// CREATURE_PART_LEFT_BICEP /// CREATURE_PART_RIGHT_SHOULDER /// CREATURE_PART_LEFT_SHOULDER /// CREATURE_PART_RIGHT_HAND /// CREATURE_PART_LEFT_HAND /// CREATURE_PART_HEAD /// - nModelNumber: CREATURE_MODEL_TYPE_* /// CREATURE_MODEL_TYPE_NONE /// CREATURE_MODEL_TYPE_SKIN (not for use on shoulders, pelvis or head). /// CREATURE_MODEL_TYPE_TATTOO (for body parts that support tattoos, i.e. not heads/feet/hands). /// CREATURE_MODEL_TYPE_UNDEAD (undead model only exists for the right arm parts). /// - oCreature: the creature to change the body part for. /// Note: Only part based creature appearance types are supported. /// i.e. The model types for the playable races ('P') in the appearance.2da /// </summary> public static void SetCreatureBodyPart(CreaturePart nPart, int nModelNumber, uint oCreature = OBJECT_INVALID) { Internal.NativeFunctions.StackPushObject(oCreature); Internal.NativeFunctions.StackPushInteger(nModelNumber); Internal.NativeFunctions.StackPushInteger((int)nPart); Internal.NativeFunctions.CallBuiltIn(793); }
private static CreaturePart CreateTorso(Vector3 position, Quaternion rotation) { var torso = new CreaturePart(); GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere); go.name = "Torso"; go.transform.position = position; go.transform.rotation = rotation; go.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f); go.layer = LayerMask.NameToLayer(CreatureFactory.CreatureLayerName); torso.Transform = go.transform; torso.Rigidbody = go.AddComponent <Rigidbody>(); torso.Rigidbody.mass = 20f; torso.Rigidbody.drag = 0.05f; //torso.Rigidbody.inertiaTensor *= 2f; // torso.Rigidbody.isKinematic = true; go.AddComponent <CreatureCollider>(); go.AddComponent <VelocitySensor>(); go.AddComponent <AngleSensor>(); return(torso); }
private GameObject GenerateFin(float scale, CreaturePart cp, Boid boid, float rotationOffset, GameObject part, FinAnimator.Side side) { GameObject fin = null; Vector3 pos = cp.position; float rotOffset = finRotatorOffset; switch (side) { case FinAnimator.Side.left: fin = GameObject.Instantiate <GameObject>(leftFinPrefab); pos -= (transform.right * cp.size / 2); break; case FinAnimator.Side.right: fin = GameObject.Instantiate <GameObject>(rightFinPrefab); pos += (transform.right * cp.size / 2); rotOffset = -rotOffset; break; } pos += rotOffset * transform.right * scale; fin.transform.position = pos; fin.transform.rotation = fin.transform.rotation * transform.rotation; if (scaleFins) { fin.transform.localScale = new Vector3(scale, scale, scale); } fin.GetComponentInChildren <FinAnimator>().boid = boid; fin.GetComponentInChildren <FinAnimator>().side = side; fin.GetComponentInChildren <FinAnimator>().rotationOffset -= rotationOffset; fin.transform.parent = part.transform; return(fin); }
List <CreaturePart> CreateCreatureParams() { List <CreaturePart> list = new List <CreaturePart>(); if (headPrefab != null) { CreaturePart headPart = new CreaturePart(transform.position, headScale, CreaturePart.Part.head, headPrefab, headPrefab.transform.rotation); list.Add(headPart); } float thetaInc = Mathf.PI * 2.0f / (numTenticles); for (int i = 0; i < numTenticles; i++) { float theta = i * thetaInc; Vector3 pos = new Vector3(); pos.x = transform.position.x + Mathf.Sin(theta) * radius; pos.z = transform.position.z - Mathf.Cos(theta) * radius; pos.y = transform.position.y; Quaternion q = Quaternion.identity; q.eulerAngles = new Vector3(-tenticleAngle, Mathf.Rad2Deg * -theta, 0); // Quaternion.AngleAxis(Mathf.Rad2Deg * -theta, Vector3.up) * Quaternion.; CreaturePart cp = new CreaturePart(pos, tenticleScale , CreaturePart.Part.tenticle , tenticlePrefab, q); list.Add(cp); } return(list); }
void CreateCreature() { List <CreaturePart> parts = CreateCreatureParams(); Debug.Log("Creating creature from " + gameObject + " Parts: " + parts.Count); Boid boid = null; for (int i = 0; i < parts.Count; i++) { CreaturePart part = parts[i]; GameObject newPart = GameObject.Instantiate <GameObject>(part.prefab); newPart.transform.position = part.position; newPart.transform.rotation = part.rotation; newPart.transform.localScale = new Vector3(part.size, part.size, part.size); newPart.transform.parent = transform; Boid thisBoid = newPart.GetComponentInChildren <Boid>(); if (thisBoid != null) { boid = thisBoid; newPart.transform.parent = boid.transform.GetChild(0).transform; } FinAnimator anim = newPart.GetComponentInChildren <FinAnimator>(); if (anim != null) { newPart.transform.parent = boid.transform.GetChild(0).transform; anim.boid = boid; } } }
private static CreaturePart CreateBody(Vector3 position, Quaternion rotation) { var torso = new CreaturePart(); GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube); go.name = "Torso"; go.transform.position = position; go.transform.rotation = rotation; go.transform.localScale = new Vector3(0.5f, 0.3f, 0.5f); go.layer = LayerMask.NameToLayer(CreatureFactory.CreatureLayerName); torso.Transform = go.transform; torso.Rigidbody = go.AddComponent <Rigidbody>(); torso.Rigidbody.mass = 5f; torso.Rigidbody.drag = 1f; torso.Rigidbody.angularDrag = 1f; torso.Rigidbody.useGravity = false; torso.Rigidbody.freezeRotation = true; torso.Rigidbody.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ; // go.AddComponent<CreatureCollider>(); go.AddComponent <VelocitySensor>(); go.AddComponent <AngleSensor>(); return(torso); }
/// <summary> /// returns the model number being used for the body part and creature specified /// The model number returned is for the body part when the creature is not wearing /// armor (i.e. whether or not the creature is wearing armor does not affect /// the return value). /// Note: Only works on part based creatures, which is typically restricted to /// the playable races (unless some new part based custom content has been /// added to the module). /// returns CREATURE_PART_INVALID if used on a non-creature object, /// or if the creature does not use a part based model. /// - nPart (CREATURE_PART_*) /// CREATURE_PART_RIGHT_FOOT /// CREATURE_PART_LEFT_FOOT /// CREATURE_PART_RIGHT_SHIN /// CREATURE_PART_LEFT_SHIN /// CREATURE_PART_RIGHT_THIGH /// CREATURE_PART_LEFT_THIGH /// CREATURE_PART_PELVIS /// CREATURE_PART_TORSO /// CREATURE_PART_BELT /// CREATURE_PART_NECK /// CREATURE_PART_RIGHT_FOREARM /// CREATURE_PART_LEFT_FOREARM /// CREATURE_PART_RIGHT_BICEP /// CREATURE_PART_LEFT_BICEP /// CREATURE_PART_RIGHT_SHOULDER /// CREATURE_PART_LEFT_SHOULDER /// CREATURE_PART_RIGHT_HAND /// CREATURE_PART_LEFT_HAND /// CREATURE_PART_HEAD /// </summary> public static CreaturePart GetCreatureBodyPart(CreaturePart nCreaturePart, uint oCreature = Core.NWScript.NWScript.OBJECT_INVALID) { Internal.NativeFunctions.StackPushObject(oCreature); Internal.NativeFunctions.StackPushInteger((int)nCreaturePart); Internal.NativeFunctions.CallBuiltIn(792); return((CreaturePart)Internal.NativeFunctions.StackPopInteger()); }
/// <summary> /// Sets the armor model of this item. /// </summary> /// <param name="slot">The armor model slot index to be assigned.</param> /// <param name="value">The new model to assign.</param> public void SetArmorModel(CreaturePart slot, byte value) { int index = (int)slot; if (index >= 0 && index <= 18) { item.Item.m_nArmorModelPart[index] = value; item.Item.m_nArmorValue = item.Item.ComputeArmorClass(); } }
public TurnPartInching(CreaturePart creaturePart, Transform transform, CreatureTurnType turnType, float updateEvery, Direction hingeAxis, Transform hingeAttachedTo) : base(creaturePart, transform, CreatureTurnType.Inch, updateEvery) { state = InchState.NONE; this.hingeAxis = hingeAxis; attachedToBody = hingeAttachedTo.gameObject.AddComponent <Rigidbody>(); Initialize(hingeAxis); }
private static CreaturePart AddLegPart(CreaturePart parent, Quaternion rotationOffset, float length) { CreaturePart part = CreateCapsulePart("LegPart", length, 0.1f); part.Parent = parent; parent.Children.Add(part); part.Transform.position = GetCapsulePartTip(parent); part.Transform.rotation = part.Parent.Transform.rotation * rotationOffset; part.Transform.gameObject.layer = LayerMask.NameToLayer(CreatureFactory.CreatureLayerName); part.Rigidbody = part.Transform.gameObject.AddComponent <Rigidbody>(); part.Rigidbody.mass = 4; var j = part.Transform.gameObject.AddComponent <ConfigurableJoint>(); j.enablePreprocessing = false; j.connectedBody = parent.Transform.GetComponent <Rigidbody>(); j.xMotion = ConfigurableJointMotion.Locked; j.yMotion = ConfigurableJointMotion.Locked; j.zMotion = ConfigurableJointMotion.Locked; j.angularXMotion = ConfigurableJointMotion.Limited; j.angularYMotion = ConfigurableJointMotion.Locked; j.angularZMotion = ConfigurableJointMotion.Locked; j.lowAngularXLimit = new SoftJointLimit() { limit = -70f, bounciness = 0f, contactDistance = 0f }; j.highAngularXLimit = new SoftJointLimit() { limit = 5f, bounciness = 0f, contactDistance = 0f }; j.rotationDriveMode = RotationDriveMode.Slerp; j.slerpDrive = new JointDrive() { positionSpring = 500f, positionDamper = 20f, maximumForce = 9999999f }; part.Transform.gameObject.AddComponent <CreatureJoint>(); part.Transform.gameObject.AddComponent <CreatureCollider>(); // var claw = part.Transform.gameObject.AddComponent<CreatureClaw>(); // claw.Joint.anchor = new Vector3(0f, 0f, 0.64f); return(part); }
/// <summary> /// Gets the armor model of this item. /// </summary> /// <param name="slot">The armor model slot index to query.</param> public byte GetArmorModel(CreaturePart slot) { int index = (int)slot; if (index >= 0 && index <= 18) { return(item.Item.m_nArmorModelPart[index]); } return(0); }
private float ignoreStuckFor = 0; // disable turning on while this is + 0 public AntiGravityShieldPart(CreaturePart creaturePart, Transform transform, float updateEvery, Rigidbody bodyToShield, ActionStep.Actions[] actions) : base(creaturePart, transform, updateEvery) { this.PartType = creaturePart; this.PartTransform = transform; this.UpdateEvery = updateEvery; Activated = bodyToShield.isKinematic; this.attachedBody = bodyToShield; this._OnDuringTheseActions = actions; }
public static AudioClip GetCreaturePartAudioClip(BASE_SPECIES species, CreaturePart part) { if (species == BASE_SPECIES.Gnat) { if (part == CreaturePart.BRAKE) { return(RAKUtilities.getAudioClip("GnatBrake")); } } return(null); }
//creation public new T CreateInstance(CreaturePart part) { T instance = Activator.CreateInstance <T> (); instance.creature = part; instance.enabled = enabled; instance.priority = priority; OnCreateInstance(instance); return(instance); }
protected Dictionary <MiscVariables.AgentMiscVariables, float> miscVariables; // Misc Constants public Part(CreaturePart creaturePart, Transform transform, float updateEvery) { this.PartType = creaturePart; this.PartTransform = transform; this.UpdateEvery = updateEvery; this.parentCreature = transform.GetComponentInParent <Creature>(); this.attachedAgent = parentCreature.GetCreatureAgent(); miscVariables = MiscVariables.GetAgentMiscVariables(parentCreature); audioClip = CreatureConstants.GetCreaturePartAudioClip(parentCreature.GetBaseSpecies(), creaturePart); Enabled = true; }
public AnimationPart(CreaturePart creaturePart, Transform transform, CreatureAnimationMovementType partMovementType, float updateEvery, Vector3 movementDirection, float movementMultiplier, ActionStep.Actions[] animateDuring, PartMovesWith partMovesRelativeTo, PartAnimationType animationType, bool visibleIfNotAnimating) : base(creaturePart, transform, updateEvery) { this.movementDirection = movementDirection; this.movementMultiplier = movementMultiplier; this.AnimateDuring = animateDuring; this.partMovesRelativeTo = partMovesRelativeTo; this.animationType = animationType; this.visibleIfNotAnimating = visibleIfNotAnimating; visible = true; }
public TractorBeamAnimationPart(CreaturePart creaturePart, Transform transform, float updateEvery, Vector3 movementDirection, float movementMultiplier) : base(creaturePart, transform, CreatureAnimationMovementType.NONE, updateEvery, movementDirection, movementMultiplier, new ActionStep.Actions[] { ActionStep.Actions.Add }, PartMovesWith.TargetPosition, PartAnimationType.Particles, true) { parentCreature = transform.GetComponentInParent <Creature>(); ps = transform.GetComponent <ParticleSystem>(); mainModule = ps.main; shapeModule = ps.shape; mainModule.startSpeed = new ParticleSystem.MinMaxCurve(startSpeed); verifyParticlesAreOff(); }
private static void AddRotor(CreaturePart parent, Vector3 localPosition, Quaternion localRotation) { var thrustObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); thrustObject.transform.position = parent.Transform.position + parent.Transform.rotation * localPosition; thrustObject.transform.rotation = parent.Transform.rotation * localRotation; thrustObject.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); thrustObject.transform.parent = parent.Transform; var thruster = thrustObject.AddComponent <Thruster>(); thruster.MaxForce = 10f; thruster.Rigidbody = parent.Rigidbody; }
public BrakePart(CreaturePart creaturePart, Transform transform, float updateEvery) : base(creaturePart, transform, updateEvery) { CurrentBrakeAmount = Vector3.zero; Braking = false; AngularBraking = false; bodyToBrake = transform.GetComponent <Rigidbody>(); if (bodyToBrake == null) { bodyToBrake = transform.GetComponentInParent <Rigidbody>(); } if (bodyToBrake == null) { Debug.LogError("No rigid body found for braking part"); } }
void CreateCreature() { string[] fla = finList.Split(','); List <CreaturePart> creatureParts = CreateCreatureParams(); Gizmos.color = Color.yellow; Boid boid = null; int finNumber = 0; for (int i = 0; i < creatureParts.Count; i++) { CreaturePart cp = creatureParts[i]; GameObject part = GameObject.Instantiate <GameObject>(cp.prefab); part.transform.position = cp.position; if (i != 0) { part.transform.Translate(0, 0, partOffset); } if (i == 0) { boid = part.GetComponent <Boid>(); } else { part.transform.parent = transform; } Utilities.SetUpAnimators(part, boid); part.transform.localScale = new Vector3(cp.size * part.transform.localScale.x, cp.size * part.transform.localScale.y, cp.size * part.transform.localScale.z); part.transform.rotation = transform.rotation; part.transform.parent = transform; // Make fins if required if (System.Array.Find(fla, p => p == "" + i) != null) { float scale = cp.size / ((finNumber / 2) + 1); GameObject leftFin = GenerateFin(scale, cp, boid, (finNumber * finRotationOffset), part, FinAnimator.Side.left); GameObject rightFin = GenerateFin(scale, cp, boid, (finNumber * finRotationOffset), part, FinAnimator.Side.right); finNumber++; } } }
private static void AddLegs(CreaturePart parent) { const int numLegs = 4; const float angleBetweenLegs = 360f / numLegs; for (int i = 0; i < numLegs; i++) { Quaternion localRotation = Quaternion.Euler(0f, angleBetweenLegs * 0.5f + angleBetweenLegs * i, 0f); Vector3 localOffset = new Vector3(0f, 0f, 0.45f); Vector3 localPosition = localRotation * localOffset + Vector3.up * 0f; float legScaleMod = -0.05f * Vector3.Dot(Vector3.forward, localRotation * Vector3.forward); localRotation = localRotation * Quaternion.Euler(-20f, 0f, 0f); var legRoot = AddLegRootPart(parent, localPosition, localRotation, 0.45f + legScaleMod); var legPart = AddLegPart(legRoot, Quaternion.Euler(70f, 0f, 0f), 0.6f + legScaleMod); } }
private static void AddLegs(CreaturePart parent) { { // Left leg Quaternion localRotation = Quaternion.Euler(90f, 0f, 0f); var legRoot = AddLegRootPart(parent, new Vector3(-0.15f, 0f, 0.0f), localRotation); // var legPart = AddLegPart(legRoot, Quaternion.Euler(0f, 0f, 0f)); var foot = AddFoot(legRoot, Quaternion.Euler(-90f, 0f, 0f)); } { // Right leg Quaternion localRotation = Quaternion.Euler(90f, 0f, 0f); var legRoot = AddLegRootPart(parent, new Vector3(0.15f, 0f, 0.0f), localRotation); // var legPart = AddLegPart(legRoot, Quaternion.Euler(0f, 0f, 0f)); var foot = AddFoot(legRoot, Quaternion.Euler(-90f, 0f, 0f)); } }
private static CreaturePart CreateCapsulePart(string name, float height, float radius) { CreaturePart part = new CreaturePart(); part.Transform = new GameObject(name).transform; var c = part.Transform.gameObject.AddComponent <CapsuleCollider>(); c.direction = 2; c.height = height; c.radius = radius; c.center = new Vector3(0f, 0f, c.height * 0.5f); // Add mesh renderer as child object var meshGo = GameObject.CreatePrimitive(PrimitiveType.Capsule); Object.Destroy(meshGo.GetComponent <CapsuleCollider>()); meshGo.transform.parent = part.Transform; meshGo.transform.localScale = new Vector3(c.radius * 2f, c.height * 0.5f, c.radius * 2f); meshGo.transform.localPosition = Vector3.forward * c.height * 0.5f; meshGo.transform.localRotation = Quaternion.Euler(-90f, 0f, 0f); return(part); }
public EnginePart(CreaturePart creaturePart, Transform transform, CreatureLocomotionType partMovementType, float updateEvery) : base(creaturePart, transform, updateEvery) { }
private static Vector3 GetCapsulePartTip(CreaturePart part) { var c = part.Transform.GetComponent <CapsuleCollider>(); return(part.Transform.TransformPoint(new Vector3(0f, 0f, c.height))); }
private static CreaturePart AddFoot(CreaturePart parent, Quaternion rotationOffset) { var part = new CreaturePart(); GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube); go.name = "Foot"; go.transform.localScale = new Vector3(0.2f, 0.1f, 0.3f); go.layer = LayerMask.NameToLayer(CreatureFactory.CreatureLayerName); part.Rigidbody = go.AddComponent <Rigidbody>(); part.Rigidbody.mass = 4f; part.Rigidbody.drag = 0.1f; part.Transform = go.transform; part.Parent = parent; parent.Children.Add(part); part.Transform.position = GetCapsulePartTip(parent); part.Transform.rotation = part.Parent.Transform.rotation * rotationOffset; part.Transform.position += part.Transform.forward * 0.03f; part.Transform.gameObject.layer = LayerMask.NameToLayer(CreatureFactory.CreatureLayerName); var j = part.Transform.gameObject.AddComponent <ConfigurableJoint>(); j.anchor = new Vector3(0f, 0.5f, -0.1f); j.enablePreprocessing = false; j.connectedBody = parent.Transform.GetComponent <Rigidbody>(); j.xMotion = ConfigurableJointMotion.Locked; j.yMotion = ConfigurableJointMotion.Locked; j.zMotion = ConfigurableJointMotion.Locked; j.angularXMotion = ConfigurableJointMotion.Limited; j.angularYMotion = ConfigurableJointMotion.Locked; j.angularZMotion = ConfigurableJointMotion.Locked; j.highAngularXLimit = new SoftJointLimit() { limit = 40f, bounciness = 0f, contactDistance = 0f }; j.lowAngularXLimit = new SoftJointLimit() { limit = -40f, bounciness = 0f, contactDistance = 0f }; j.angularYLimit = new SoftJointLimit() { limit = 10f, bounciness = 0f, contactDistance = 0f }; j.angularZLimit = new SoftJointLimit() { limit = 40f, bounciness = 0f, contactDistance = 0f }; j.rotationDriveMode = RotationDriveMode.Slerp; j.slerpDrive = new JointDrive() { positionSpring = 400, positionDamper = 20, maximumForce = 9999999f }; // part.Transform.gameObject.AddComponent<CreatureCollider>(); part.Transform.gameObject.AddComponent <CreatureJoint>(); return(part); }
public void AttachPart(CreaturePart c) { attachedparts.Add(c); }