예제 #1
0
    /*
     * \brief Called whilst a collision is taking place
     */
    public void CallOnCollisionStay(Collision collision, ref CWallJump wallJump)
    {
        m_canJump = true;

        /*
         * foreach (ContactPoint contact in collision.contacts) {
         *      Debug.DrawRay(contact.point, contact.normal, Color.green);
         *
         *      // don't slide on points that arnt on the floor
         *      float yContact = collision.transform.position.y - contact.point.y;
         *      if (yContact >= 0.5f)
         *              continue;
         *
         *      // slide down slopes
         *      if (!isNearly(contact.normal.x, 0.0f, 0.01f) || !isNearly(contact.normal.z, 0.0f, 0.01f) ) {
         *              CSceneObject sceneObject = contact.otherCollider.GetComponent<CSceneObject>();
         *              float scale = 1.0f;
         *              if (sceneObject != null)
         *                      scale = sceneObject.ExtraSlide;
         *
         *              float direction = contact.normal.x < 0.0f ? -1.0f : 1.0f;
         *              m_velocity += ((((1 - contact.normal.y) * 0.25f) * direction) * scale);
         *              return;
         *      }
         * }
         */

        if (!wallJump.GetCanWallJump())
        {
            foreach (ContactPoint contact in collision.contacts)
            {
                float yContact = collision.transform.position.y - contact.point.y;
                if (yContact < 0.5f)
                {
                    continue;
                }

                // we must be colliding if we are in this method
                m_colliding = true;
                m_velocity  = (-m_direction) * 0.25f;
                return;
            }
        }
    }
    /*
     * \brief Called whilst a collision is taking place
    */
    public void CallOnCollisionStay(Collision collision, ref CWallJump wallJump)
    {
        m_canJump = true;

        /*
        foreach (ContactPoint contact in collision.contacts) {
            Debug.DrawRay(contact.point, contact.normal, Color.green);

            // don't slide on points that arnt on the floor
            float yContact = collision.transform.position.y - contact.point.y;
            if (yContact >= 0.5f)
                continue;

            // slide down slopes
            if (!isNearly(contact.normal.x, 0.0f, 0.01f) || !isNearly(contact.normal.z, 0.0f, 0.01f) ) {
                CSceneObject sceneObject = contact.otherCollider.GetComponent<CSceneObject>();
                float scale = 1.0f;
                if (sceneObject != null)
                    scale = sceneObject.ExtraSlide;

                float direction = contact.normal.x < 0.0f ? -1.0f : 1.0f;
                m_velocity += ((((1 - contact.normal.y) * 0.25f) * direction) * scale);
                return;
            }
        }
        */

        if (!wallJump.GetCanWallJump()) {
            foreach (ContactPoint contact in collision.contacts) {
                float yContact = collision.transform.position.y - contact.point.y;
                if (yContact < 0.5f)
                    continue;

                // we must be colliding if we are in this method
                m_colliding = true;
                m_velocity = (-m_direction) * 0.25f;
                return;
            }
        }
    }
    /*
     * \brief Initialise anything we don't know at construct time
    */
    public void Create(CEntityPlayer player, Rigidbody body)
    {
        m_body = body;
        m_player = player;
        m_wallJump = player.GetComponent<CWallJump>();
        m_ladderClimb = new CLadderClimb();

        //m_ledgeGrabBox = transform.Find("Ledge_Grab_Detection").gameObject;

        m_invert = InsideTower ? -1 : 1;
    }
    /*
     * \brief Called when the object is created. At the start.
     *        Only called once per instaniation.
    */
    public override void Start()
    {
        base.Start();

        m_playerPositionAlpha = InitialAlphaPosition;
        m_name = "Player";

        m_physics = GetComponent<CPlayerPhysics>();
        m_physics.Create(GetComponent<Rigidbody>());

        m_cameraClass = MainCamera.GetComponent<CCamera>();

        m_wallJump = GetComponent<CWallJump>();

        m_animation = GetComponentInChildren<Animation>();

        m_playerHealth = MaxHealth;

        m_idleAnimations[0] = "idle";
        m_idleAnimations[1] = "idle0";
        m_idleAnimations[2] = "idle1";

        m_footSteps = GetComponent<AudioSource>();
    }
    /*
     * \brief Called when the object is created. At the start.
     *        Only called once per instaniation.
    */
    public override void Start()
    {
        base.Start();

        m_playerPositionAlpha = InitialAlphaPosition;
        m_name = "Player";

        m_physics = GetComponent<CPlayerPhysics>();
        m_physics.Create(GetComponent<Rigidbody>());

        m_cameraClass = MainCamera.GetComponent<CCamera>();

        m_wallJump = GetComponent<CWallJump>();

        m_animation = GetComponent<CPlayerAnimation>();
        m_animation.OnStart(GetComponentInChildren<Animation>());

        m_playerHealth = MaxHealth;

        m_footSteps = GetComponent<AudioSource>();

        this.transform.GetChild(0).transform.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y + 90, 0));
    }