private void OnCollisionEnter(Collision collision) { if (currentState == CREATURE_STATE.DEAD) { return; } agent.OnCollisionEnter(collision); if (agent.GetRigidBody().velocity.magnitude > agent.maxVelocityMagnitude * 2) { if (currentState != CREATURE_STATE.DEAD) { SetStateToDead(CREATURE_DEATH_CAUSE.FlightCollision); } } }
public static void CreatureAgentInitialize(BASE_SPECIES baseSpecies, CreatureAgent agent) { if (baseSpecies == BASE_SPECIES.Gnat) { agent.GetRigidBody().constraints = RigidbodyConstraints.None; agent.SetTurnSpeed(.3f); agent.SetSustainHeight(5); agent.SetMaxAngularVel(10); agent.SetMaxVelocityMagnitude(20); agent.SetCruisingSpeed(new Vector3(2, 1, 15)); // Maximum force of the constant force component // agent.maxForce.y = 15; agent.maxForce.z = 8; agent.maxForce.x = 4; // Amount of force needed to hold the objects weight // agent.SetMinimumForceToHover(8); agent.SetSlowDownModifier(1); agent.GetRigidBody().maxAngularVelocity = 5; agent.SetExploreRadiusModifier(200); agent.SetGrabType(CreatureGrabType.TractorBeam); BuildCreatureParts(baseSpecies, agent); } else if (baseSpecies == BASE_SPECIES.Gagk) { agent.SetTurnSpeed(1f); agent.SetSustainHeight(1); agent.SetMaxAngularVel(15); agent.SetMaxVelocityMagnitude(10); agent.SetCruisingSpeed(new Vector3(0, 0, 5)); // Maximum force of the constant force component // agent.maxForce.y = 0; agent.maxForce.z = 5; agent.maxForce.x = 0; // Amount of force needed to hold the objects weight // agent.SetMinimumForceToHover(0); agent.SetSlowDownModifier(15); agent.SetExploreRadiusModifier(200); BuildCreatureParts(baseSpecies, agent); } }
public static void BuildCreatureParts(BASE_SPECIES baseSpecies, CreatureAgent agent) { Creature creature = agent.creature; Rigidbody rigidbody = agent.GetRigidBody(); List <Part> allParts = new List <Part>(); if (baseSpecies == BASE_SPECIES.Gnat) { // Body with constant force // EnginePart bodyFlight = new EnginePart (CreaturePart.BODY, creature.transform.GetChild(0), CreatureLocomotionType.Flight, .2f); // Body with Rotation turning // TurnPart bodyTurning = new TurnPartRotation (CreaturePart.BODY, creature.transform.GetChild(0), CreatureTurnType.Rotate, .2f); // Backward Propeller // AnimationPart zPropeller = new AnimationPart(CreaturePart.ENGINE_Z, creature.transform.GetChild(1), CreatureAnimationMovementType.Rotation, .05f, Vector3.up, 10, new ActionStep.Actions[] { ActionStep.Actions.Add, ActionStep.Actions.Land, ActionStep.Actions.MoveTo, ActionStep.Actions.Wait, ActionStep.Actions.Sleep }, PartMovesWith.ConstantForceZ, PartAnimationType.Movement, true); // Y Propellers // AnimationPart yPropeller = new AnimationPart(CreaturePart.ENGINE_Y, creature.transform.GetChild(3), CreatureAnimationMovementType.Rotation, .05f, Vector3.up, 10, new ActionStep.Actions[] { ActionStep.Actions.Add, ActionStep.Actions.Land, ActionStep.Actions.MoveTo, ActionStep.Actions.Wait, ActionStep.Actions.Sleep }, PartMovesWith.ConstantForceY, PartAnimationType.Movement, true); AnimationPart yPropeller2 = new AnimationPart(CreaturePart.ENGINE_Y, creature.transform.GetChild(4), CreatureAnimationMovementType.Rotation, .05f, Vector3.up, 10, new ActionStep.Actions[] { ActionStep.Actions.Add, ActionStep.Actions.Land, ActionStep.Actions.MoveTo, ActionStep.Actions.Wait, ActionStep.Actions.Sleep }, PartMovesWith.ConstantForceY, PartAnimationType.Movement, true); AnimationPart yPropeller3 = new AnimationPart(CreaturePart.ENGINE_Y, creature.transform.GetChild(5), CreatureAnimationMovementType.Rotation, .05f, Vector3.up, 10, new ActionStep.Actions[] { ActionStep.Actions.Add, ActionStep.Actions.Land, ActionStep.Actions.MoveTo, ActionStep.Actions.Wait, ActionStep.Actions.Sleep }, PartMovesWith.ConstantForceY, PartAnimationType.Movement, true); AnimationPart yPropeller4 = new AnimationPart(CreaturePart.ENGINE_Y, creature.transform.GetChild(6), CreatureAnimationMovementType.Rotation, .05f, Vector3.up, 10, new ActionStep.Actions[] { ActionStep.Actions.Add, ActionStep.Actions.Land, ActionStep.Actions.MoveTo, ActionStep.Actions.Wait, ActionStep.Actions.Sleep }, PartMovesWith.ConstantForceY, PartAnimationType.Movement, true); // Antigrav Shield // AntiGravityShieldPart shieldPart = new AntiGravityShieldPart(CreaturePart.SHIELD, creature.transform.GetChild(9), .2f, creature.GetCreatureAgent().GetRigidBody(), new ActionStep.Actions[] { ActionStep.Actions.Add, ActionStep.Actions.Locate, ActionStep.Actions.None, ActionStep.Actions.Wait }); AnimationPart antiGravShieldAnimation = new AnimationPart(CreaturePart.SHIELD, creature.transform.GetChild(7), CreatureAnimationMovementType.Rotation, .05f, Vector3.up, 10, new ActionStep.Actions[] { ActionStep.Actions.Add, ActionStep.Actions.MoveTo, ActionStep.Actions.Add, ActionStep.Actions.Eat , ActionStep.Actions.Locate, ActionStep.Actions.None, ActionStep.Actions.Wait }, PartMovesWith.IsKinematic, PartAnimationType.Movement, false); // Tractor Beam // TractorBeamPart tractorBeam = new TractorBeamPart(creature.transform, .2f, 30); TractorBeamAnimationPart tractorAnimation = new TractorBeamAnimationPart(CreaturePart.TRACTORBEAM, creature.transform.GetChild(8), .2f, Vector3.forward, .3f); allParts.Add(bodyFlight); allParts.Add(bodyTurning); allParts.Add(zPropeller); allParts.Add(yPropeller); allParts.Add(yPropeller2); allParts.Add(yPropeller3); allParts.Add(yPropeller4); allParts.Add(shieldPart); allParts.Add(antiGravShieldAnimation); allParts.Add(tractorBeam); allParts.Add(tractorAnimation); agent.SetCreatureTurnType(CreatureTurnType.Rotate); agent.setParts(allParts); } else if (baseSpecies == BASE_SPECIES.Gagk) { // Constant force for Z // EnginePart mainEngine = new EnginePart(CreaturePart.ENGINE_Z, creature.transform.GetChild(0), CreatureLocomotionType.StandardForwardBack, 1); TurnPart inchSpine = new TurnPartInching(CreaturePart.BODY, creature.transform.GetChild(0), CreatureTurnType.Inch, .5f, Direction.X, creature.transform.GetChild(1)); allParts.Add(mainEngine); allParts.Add(inchSpine); agent.SetCreatureTurnType(CreatureTurnType.Inch); agent.setParts(allParts); } }