示例#1
0
 //Called by Unity upon adding a new component to an object, or when Reset is selected in the context menu. Used here to provide default values.
 //Also used when fixing up components using the CharacterFixEditor button
 void Reset()
 {
     m_RigidBody          = transform.GetComponent <Rigidbody>();
     m_ControlledCollider = transform.GetComponent <ControlledCapsuleCollider>();
     m_CapsuleCollider    = transform.GetComponent <CapsuleCollider>();
     m_CheckDistance      = 0.02f;
     m_SquishRadius       = 0.05f;
 }
 //Called by Unity upon adding a new component to an object, or when Reset is selected in the context menu. Used here to provide default values.
 //Also used when fixing up components using the CharacterFixEditor button
 void Reset()
 {
     m_ControlledCollider           = transform.GetComponent <ControlledCapsuleCollider> ();
     m_ApplyRotationCorrection      = true;
     m_ApplyLastMovementAsVelocity  = false;
     m_DisableDownwardsLastMovement = false;
     m_UseEscapeAcceleration        = false;
     m_EscapeAcceleration           = 10.0f;
 }
示例#3
0
    public void OverrideValues(CapsuleTransform a_ToCopyFrom)
    {
        m_CapsuleCollider  = a_ToCopyFrom.m_CapsuleCollider;
        m_Position         = a_ToCopyFrom.m_Position;
        m_UpDirection      = a_ToCopyFrom.m_UpDirection;
        m_Length           = a_ToCopyFrom.m_Length;
        m_LastResizeMethod = a_ToCopyFrom.m_LastResizeMethod;

        if (!m_IsCopy && m_CapsuleCollider != null)
        {
            m_CapsuleCollider.transform.position = m_Position;
            m_CapsuleCollider.transform.rotation = GetRotation();
        }
    }
示例#4
0
    void OnTriggerEnter(Collider a_Collider)
    {
        ControlledCapsuleCollider controlledCapsuleCollider = a_Collider.GetComponent <ControlledCapsuleCollider>();

        if (controlledCapsuleCollider != null)
        {
            //Prevent death state to be used if the collider is no-clipping
            if (controlledCapsuleCollider.AreCollisionsActive())
            {
                Debug.Log("Death triggered by: " + transform.name);
                if (InSceneLevelSwitcher.Get())
                {
                    InSceneLevelSwitcher.Get().Respawn();
                }
            }
        }
    }
 public override void InitModule(CharacterControllerBase a_CharacterController)
 {
     base.InitModule(a_CharacterController);
     m_CharacterController = a_CharacterController as GroundedCharacterController;
     m_ControlledCollider  = a_CharacterController.GetCollider() as ControlledCapsuleCollider;
 }
示例#6
0
 public void Init(ControlledCapsuleCollider a_CapsuleCollider)
 {
     m_CapsuleCollider = a_CapsuleCollider;
 }
    public static void ShowTab(CharacterControllerBase a_CharacterController)
    {
        if (a_CharacterController == null)
        {
            GUILayout.Label("CharacterController script not found on object", EditorStyles.boldLabel);
            return;
        }

        GroundedCharacterController groundedChar = (GroundedCharacterController)a_CharacterController;
        ControlledCapsuleCollider   capsuleCol   = (ControlledCapsuleCollider)a_CharacterController.GetCollider();

        if (groundedChar && capsuleCol)
        {
            SerializedObject charObject = new SerializedObject(groundedChar);
            SerializedObject colObject  = new SerializedObject(capsuleCol);
            EditorGUI.BeginChangeCheck();

            float prevLabelWidth = EditorGUIUtility.labelWidth;
            EditorGUIUtility.labelWidth += 50.0f;

            GUILayout.Label("Variables for movement", EditorStyles.boldLabel);
            GUILayout.Space(4.0f);

            if (EditorHelp.Foldout("Basic character settings"))
            {
                EditorGUI.indentLevel++;
                EditorHelp.SerializeRelativeField(colObject, "m_LayerMask", "", "Collision mask");
                EditorHelp.SerializeRelativeField(colObject, "m_Length", "The length of the capsule (not including both demispheres)", "Capsule length");
                EditorHelp.SerializeRelativeField(colObject, "m_Radius", "The radius of the capsule", "Capsule radius");
                EditorHelp.SerializeRelativeField(charObject, "m_Gravity", "How fast a character falls downwards");
                EditorHelp.SerializeRelativeField(charObject, "m_DragConstant", "A force that slows down the character (low values work best!)", "Drag");
                GUILayout.Space(4.0f);
                EditorGUI.indentLevel--;
            }

            if (EditorHelp.Foldout("Running"))
            {
                EditorGUI.indentLevel++;
                EditorHelp.SerializeRelativeField(charObject, "m_WalkForce", "How fast a character can accelerate", "Character acceleration");
                EditorHelp.SerializeRelativeField(charObject, "m_WalkForceApplyLimit", "The maximum speed a character can accelerate to by running", "Max running speed");
                EditorHelp.SerializeRelativeField(charObject, "m_StoppingForce", "How fast a character can stop running when the player releases run input", "Brake deceleration");
                EditorHelp.SerializeRelativeField(charObject, "m_ApplyStoppingForceWhenActivelyBraking", "Whether the character uses Brake deceleration when the player turns around mid-run (prevents sliding)", "Brake when changing direction");
                EditorHelp.SerializeRelativeField(charObject, "m_FrictionConstant", "Slows down the character when its on the ground", "Friction");
                GUILayout.Space(4.0f);
                EditorGUI.indentLevel--;
            }

            if (EditorHelp.Foldout("Jumping"))
            {
                EditorGUI.indentLevel++;
                EditorHelp.SerializeRelativeField(charObject, "m_JumpVelocity", "The velocity that is applied to the character on jump", "Jump velocity");
                EditorHelp.SerializeRelativeField(charObject, "m_JumpCutVelocity", "The vertical velocity that the character will use when the jump button is let go after jumping (this leads to different jump heights)", "Low jump velocity");
                EditorHelp.SerializeRelativeField(charObject, "m_MinAllowedJumpCutVelocity", "If the jump button is let go after jumping, and its vertical velocity is below this threshold, the character will switch to Low jump velocity (value above this one) ", "Velocity threshold for low jump");
                EditorHelp.SerializeRelativeField(charObject, "m_HorizontalJumpBoostFactor", "How much of the horizontal velocity should be added to the character's velocity when jumping", "Horizontal jump boost factor", "range01");
                EditorHelp.SerializeRelativeField(charObject, "m_JumpAlignedToGroundFactor", "How much the jump direction should be influenced by the ground (0 is jumping straight up, 1 is jumping away from the ground)", "Jump aligned to ground factor", "range01");
                EditorHelp.SerializeRelativeField(charObject, "m_GroundedToleranceTime", "The time (in seconds) after not being grounded where a jump press is still valid. If a player presses jump just after falling off a platform, the character will still jump. ", "Jump grounded tolerance time");
                EditorHelp.SerializeRelativeField(charObject, "m_JumpCacheTime", "The time (in seconds) after which a jump press is still valid. If a player presses jump before standing on the ground, but lands within this amount of seconds, the character will still jump", "Jump input valid time");
                EditorHelp.SerializeRelativeField(charObject, "m_ResetVerticalSpeedOnJumpIfMovingDown", "If the character is running downhill and the player presses jump, should the downwards velocity be reset before jumping? Could otherwise lead to low jumps in this situation", "Reset down velocity on jump");
                GUILayout.Space(4.0f);
                EditorGUI.indentLevel--;
            }
            if (EditorHelp.Foldout("Air control"))
            {
                EditorGUI.indentLevel++;
                EditorHelp.SerializeRelativeField(charObject, "m_AirControl", "How fast a character can accelerate in the air (as a factor of its regular acceleration). 0 is no acceleration, 1 is just as fast as on the ground", "In-air character acceleration", "range01");
                EditorHelp.SerializeRelativeField(charObject, "m_AirForceApplyLimit", "The maximum speed a character can accelerate to by moving in the air. ", "Max horizontal in-air speed");
                GUILayout.Space(4.0f);
                EditorGUI.indentLevel--;
            }
            if (EditorHelp.Foldout("Environmental context"))
            {
                EditorGUI.indentLevel++;
                EditorHelp.SerializeRelativeField(colObject, "m_MaximumGroundedAngle", "The maximum angle a character can still walk on(from straight up)", "Max ground angle");
                EditorHelp.SerializeRelativeField(colObject, "m_MaximumWallAngle", "The maximum angle a character can still align to a wall with(from straight up)", "Max wall angle");
                EditorHelp.SerializeRelativeField(colObject, "m_MaxGrabAngle", "The maximum angle of the surface on a ledge where a character can still grab on to (from straight up)", "Max edge ground angle");
                EditorHelp.SerializeRelativeField(colObject, "m_MaxEdgeAlignAngle", "The maximum angle of the wall before a ledge where a character can still align to (from straight up)", "Max edge wall angle");
                GUILayout.Space(4.0f);
                EditorGUI.indentLevel--;
            }
            if (EditorHelp.Foldout("Various"))
            {
                EditorGUI.indentLevel++;
                EditorHelp.SerializeRelativeField(charObject, "m_ApplyGravityOnGround", "Should the character apply gravity when it's standing on the ground?", "Gravity active on ground");
                if (charObject.FindProperty("m_ApplyGravityOnGround").boolValue)
                {
                    EditorHelp.SerializeRelativeField(charObject, "m_ApplyGravityIntoGroundNormal", "Should the gravity on the ground be pointed in the direction of the ground (when checked), or should it point straight down (when unchecked)? If unchecked, gravity will pull the character downhill", "Gravity directed into ground");
                }
                GUILayout.Space(4.0f);
                EditorGUI.indentLevel--;
            }

            EditorGUIUtility.labelWidth = prevLabelWidth;

            if (EditorGUI.EndChangeCheck())
            {
                charObject.ApplyModifiedProperties();
                colObject.ApplyModifiedProperties();
            }
        }
        else
        {
            if (!groundedChar)
            {
                GUILayout.Label("This is not a grounded character controller", EditorStyles.boldLabel);
            }
            if (!capsuleCol)
            {
                GUILayout.Label("This character does not have a controlled capsule collider script", EditorStyles.boldLabel);
            }
        }
    }
 public void Init(ControlledCapsuleCollider a_CapsuleCollider)
 {
     m_GroundedInfo.Init(a_CapsuleCollider);
     m_SideCastInfo.Init(a_CapsuleCollider);
     m_EdgeCastInfo.Init(a_CapsuleCollider);
 }
    public static bool IsCharacterAlright(GameObject a_Object)
    {
        if (a_Object == null)
        {
            return(false);
        }
        GroundedCharacterController character = a_Object.GetComponent <GroundedCharacterController>();

        if (character == null)
        {
            return(false);
        }
        ControlledCapsuleCollider controlledCapsuleCollider = a_Object.GetComponent <ControlledCapsuleCollider>();

        if (controlledCapsuleCollider == null)
        {
            return(false);
        }
        PlayerInput input = a_Object.GetComponent <PlayerInput>();

        if (input == null)
        {
            return(false);
        }
        if (!input.DoesInputExist("Move") || !input.DoesInputExist("Jump"))
        {
            return(false);
        }
        AbilityModuleManager abilityModuleManager = a_Object.GetComponent <AbilityModuleManager>();

        if (abilityModuleManager == null)
        {
            return(false);
        }
        CapsuleMovingColliderSolver capsuleMovingColliderSolver = a_Object.GetComponent <CapsuleMovingColliderSolver>();

        if (capsuleMovingColliderSolver == null)
        {
            return(false);
        }
        CapsuleCollider capsuleCollider = a_Object.GetComponent <CapsuleCollider>();

        if (capsuleCollider == null)
        {
            return(false);
        }
        Rigidbody rigidbody = a_Object.GetComponent <Rigidbody>();

        if (rigidbody == null)
        {
            return(false);
        }
        if (rigidbody.constraints != RigidbodyConstraints.FreezeAll || rigidbody.useGravity != false || rigidbody.angularDrag != 0.0f)
        {
            return(false);
        }
        CapsuleVolumeIntegrity volumeIntegrity = a_Object.GetComponent <CapsuleVolumeIntegrity>();

        if (volumeIntegrity == null)
        {
            return(false);
        }

        SerializedObject serializedObject = new SerializedObject(character);

        if (serializedObject.FindProperty("m_ControlledCollider").objectReferenceValue == null)
        {
            return(false);
        }
        if (serializedObject.FindProperty("m_AbilityManager").objectReferenceValue == null)
        {
            return(false);
        }

        serializedObject = new SerializedObject(controlledCapsuleCollider);
        if (serializedObject.FindProperty("m_CapsuleMovingColliderSolver").objectReferenceValue == null)
        {
            return(false);
        }
        if ((1 << a_Object.layer & serializedObject.FindProperty("m_LayerMask").intValue) != 0 ||
            (1 << LayerMask.NameToLayer("Ignore Raycast") & serializedObject.FindProperty("m_LayerMask").intValue) != 0)
        {
            return(false);
        }

        serializedObject = new SerializedObject(input);
        if (serializedObject.FindProperty("m_CharacterController").objectReferenceValue == null)
        {
            return(false);
        }

        serializedObject = new SerializedObject(capsuleMovingColliderSolver);
        if (serializedObject.FindProperty("m_ControlledCollider").objectReferenceValue == null)
        {
            return(false);
        }

        serializedObject = new SerializedObject(volumeIntegrity);
        if (serializedObject.FindProperty("m_RigidBody").objectReferenceValue == null)
        {
            return(false);
        }
        if (serializedObject.FindProperty("m_ControlledCollider").objectReferenceValue == null)
        {
            return(false);
        }
        if (serializedObject.FindProperty("m_CapsuleCollider").objectReferenceValue == null)
        {
            return(false);
        }

        return(true);
    }
示例#10
0
    static void FixCharacterOnObject(GameObject a_Object)
    {
        //Find, or create missing components
        GroundedCharacterController character = a_Object.GetComponent <GroundedCharacterController>();

        if (character == null)
        {
            character = a_Object.AddComponent <GroundedCharacterController>();
        }
        ControlledCapsuleCollider controlledCapsuleCollider = a_Object.GetComponent <ControlledCapsuleCollider>();

        if (controlledCapsuleCollider == null)
        {
            controlledCapsuleCollider = a_Object.AddComponent <ControlledCapsuleCollider>();
        }
        PlayerInput input = a_Object.GetComponent <PlayerInput>();

        if (input == null)
        {
            input = a_Object.AddComponent <PlayerInput>();
        }
        input.EnsureJumpAndMoveInputsAreSet();
        AbilityModuleManager abilityModuleManager = a_Object.GetComponent <AbilityModuleManager>();

        if (abilityModuleManager == null)
        {
            abilityModuleManager = a_Object.AddComponent <AbilityModuleManager>();
        }
        CapsuleMovingColliderSolver capsuleMovingColliderSolver = a_Object.GetComponent <CapsuleMovingColliderSolver>();

        if (capsuleMovingColliderSolver == null)
        {
            capsuleMovingColliderSolver = a_Object.AddComponent <CapsuleMovingColliderSolver>();
        }
        CapsuleCollider capsuleCollider = a_Object.GetComponent <CapsuleCollider>();

        if (capsuleCollider == null)
        {
            capsuleCollider = a_Object.AddComponent <CapsuleCollider>();
        }
        Rigidbody rigidbody = a_Object.GetComponent <Rigidbody>();

        if (rigidbody == null)
        {
            rigidbody = a_Object.AddComponent <Rigidbody>();
        }
        rigidbody.constraints = RigidbodyConstraints.FreezeAll;
        rigidbody.useGravity  = false;
        rigidbody.angularDrag = 0.0f;
        CapsuleVolumeIntegrity volumeIntegrity = a_Object.GetComponent <CapsuleVolumeIntegrity>();

        if (volumeIntegrity == null)
        {
            volumeIntegrity = a_Object.AddComponent <CapsuleVolumeIntegrity>();
        }


        //Link up the components to one another, using the serializedobject interface
        SerializedObject serializedObject = new SerializedObject(character);

        serializedObject.FindProperty("m_ControlledCollider").objectReferenceValue = controlledCapsuleCollider as ControlledCollider;
        serializedObject.FindProperty("m_AbilityManager").objectReferenceValue     = abilityModuleManager;
        serializedObject.ApplyModifiedProperties();

        serializedObject = new SerializedObject(controlledCapsuleCollider);
        serializedObject.FindProperty("m_CapsuleMovingColliderSolver").objectReferenceValue = capsuleMovingColliderSolver;
        if ((1 << a_Object.layer & serializedObject.FindProperty("m_LayerMask").intValue) != 0 ||
            (1 << LayerMask.NameToLayer("Ignore Raycast") & serializedObject.FindProperty("m_LayerMask").intValue) != 0)
        {
            serializedObject.FindProperty("m_LayerMask").intValue = ~((1 << a_Object.layer) + (1 << LayerMask.NameToLayer("Ignore Raycast")));
        }
        serializedObject.ApplyModifiedProperties();

        serializedObject = new SerializedObject(input);
        serializedObject.FindProperty("m_CharacterController").objectReferenceValue = character as CharacterControllerBase;
        serializedObject.ApplyModifiedProperties();

        serializedObject = new SerializedObject(capsuleMovingColliderSolver);
        serializedObject.FindProperty("m_ControlledCollider").objectReferenceValue = controlledCapsuleCollider;
        serializedObject.ApplyModifiedProperties();

        serializedObject = new SerializedObject(volumeIntegrity);
        serializedObject.FindProperty("m_RigidBody").objectReferenceValue          = rigidbody;
        serializedObject.FindProperty("m_ControlledCollider").objectReferenceValue = controlledCapsuleCollider;
        serializedObject.FindProperty("m_CapsuleCollider").objectReferenceValue    = capsuleCollider;
        serializedObject.ApplyModifiedProperties();
    }