예제 #1
0
        public void Init(int index = 0)
        {
            _sword                = GetComponentInChildren <EnemySword>();
            _animator             = GetComponent <Animator>();
            _navMeshAgent         = GetComponent <NavMeshAgent>();
            _navMeshAgent.speed   = _normalSpeed;
            _navMeshAgent.enabled = true;

            var ragDollColliders      = GetComponentsInChildren <CapsuleCollider>();
            var rigidbodyBoxcolliders = GetComponentsInChildren <BoxCollider>();

            var capsuleCollider = gameObject.AddComponent <CapsuleCollider>();

            capsuleCollider.height = 1.756473f;
            capsuleCollider.radius = 0.3f;
            capsuleCollider.center = new Vector3(0, 0.8717635f, 0);

            var ragdollRigidBodies = GetComponentsInChildren <Rigidbody>();

            _ragdoll = new Ragdoll(ragDollColliders, ragdollRigidBodies, rigidbodyBoxcolliders, capsuleCollider,
                                   _animator);
            _ragdoll.DisableRagdoll(ragdollRigidBodies);

            _rigidbody                        = gameObject.AddComponent <Rigidbody>();
            _rigidbody.constraints            = RigidbodyConstraints.FreezeRotation;
            _rigidbody.collisionDetectionMode = CollisionDetectionMode.Continuous;
            _rigidbody.mass                   = 50;
        }
예제 #2
0
        public void Init(int index)
        {
            _index = index;
            var model = transform.GetChild(index);

            model.gameObject.SetActive(true);

            _pickup           = new Pickup();
            _interact         = new Interact();
            _jump             = new Jump();
            _playerController = new PlayerController();
            _inputHandler     = new InputHandler();

            // Find rigidbody colliders
            var rigidBodyColliders    = GetComponentsInChildren <CapsuleCollider>();
            var rigidbodyBoxcolliders = GetComponentsInChildren <BoxCollider>();

            // Add player collider
            var capsuleCollider = gameObject.AddComponent <CapsuleCollider>();

            capsuleCollider.height = 1.98f;
            capsuleCollider.radius = 0.5f;
            capsuleCollider.center = new Vector3(0, 1, 0);

            _ragdollRigidBodies = GetComponentsInChildren <Rigidbody>();
            _ragdoll            = new Ragdoll(rigidBodyColliders, _ragdollRigidBodies, rigidbodyBoxcolliders, capsuleCollider, GetComponentInChildren <Animator>());
            _ragdoll.DisableRagdoll(_ragdollRigidBodies);

            // Enable trigger collider
            _triggerCollider         = GetComponent <BoxCollider>();
            _triggerCollider.enabled = true;

            _rigidbody                        = gameObject.AddComponent <Rigidbody>();
            _rigidbody.constraints            = RigidbodyConstraints.FreezeRotation;
            _rigidbody.collisionDetectionMode = CollisionDetectionMode.Continuous;
            _rigidbody.mass                   = 50;
            _rigidbody.drag                   = 0f;

            _animationController = new AnimationController(GetComponentInChildren <Animator>(), _rigidbody, _pickup, _jump);

            _pickup.Init(transform, _animationController, GetComponentInChildren <RightArmTarget>());
            _interact.Init(_animationController);
            _jump.Init(transform);

            _respawnable = GetComponent <Respawnable>();
            _drown       = GetComponent <Drown>();
        }