Ejemplo n.º 1
0
    private new void Update()
    {
        switch (state)
        {
        case GruntState.Moving:
            setAngle();
            body.AddForce(transform.right * moveForce);
            break;

        case GruntState.Attacking:
            if (target.dead)
            {
                state = GruntState.Moving;
            }
            attackCooldown -= Time.deltaTime;
            if (attackCooldown <= 0)
            {
                target.takeDamage(1);
                attackCooldown = 1f;
            }
            break;
        }

        body.velocity = body.velocity * 0.9f;
    }
Ejemplo n.º 2
0
    public void OnUpdate(ref GruntState playerState)
    {
        if (playerState == GruntState.Standing)
        {
            m_body.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
        }


        m_isJumpDown = false;         //= Input.GetButton("Jump");
        //if (Application.platform == RuntimePlatform.Android)
        //	m_isJumpDown = Input.touchCount != 0;

        if (m_isJumpDown && m_jumpState == JumpState.Landed && CanJump(playerState))
        {
            if ((Time.time * 1000.0f) - m_jumpTimer > JumpDelayMS)
            {
                m_jumpTimer = (Time.time * 1000.0f);
                m_body.AddForce(new Vector3(0, PlayerJumpHeight, 0), ForceMode.Impulse);
                m_jumpState      = JumpState.Jumping;
                playerState      = GruntState.Jumping;
                m_collisionState = CollisionState.None;
            }
        }

        if (m_jumpState == JumpState.Jumping && playerState == GruntState.Jumping)
        {
            if ((Time.time * 1000.0f) - m_jumpTimer > 2000.0f)
            {
                playerState = GruntState.FallJumping;
            }
        }
    }
Ejemplo n.º 3
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.CompareTag("Attackable"))
     {
         target = collision.gameObject.GetComponent <Attackable>();
         state  = GruntState.Attacking;
     }
 }
 public void OnFixedUpdate(ref GruntState playerState, CGruntPhysics physics, FootMaterial footMaterial)
 {
     if (playerState == GruntState.Walking)
     {
         m_currentAnimation = "walk";
         if (!m_animation.IsPlaying("walk"))
         {
             m_animation.CrossFade("walk", 0.2f);
             PlayFootstepAudio(footMaterial);
         }
     }
     else if (playerState == GruntState.Turning)
     {
         m_currentAnimation = "running-turn";
         if (!m_animation.IsPlaying("running-turn") && !m_startedTurningRound)
         {
             m_startedTurningRound = true;
             m_animation["running-turn"].speed = 1.2f;
             m_animation.CrossFade("running-turn");
         }
         else if (!m_animation.IsPlaying("running-turn"))
         {
             m_startedTurningRound = false;
             playerState = GruntState.Walking;
         }
     }
     else if (playerState == GruntState.Standing)
     {
         if (!m_animation.IsPlaying(m_lastKnownIdle))
         {
             m_currentAnimation = "idle-" + Random.Range(0, 2);
             m_lastKnownIdle = m_currentAnimation;
             m_animation[m_currentAnimation].speed = Random.Range(10, 30) / 100.0f;
             m_animation.CrossFade(m_currentAnimation);
         }
     }
     else if (playerState == GruntState.Jumping)
     {
         m_currentAnimation = "run-jump";
         if (!m_animation.IsPlaying("run-jump"))
             m_animation.Play("run-jump");
     }
     else if (playerState == GruntState.FallJumping)
     {
         m_currentAnimation = "falling";
         if (!m_animation.IsPlaying("falling"))
             m_animation.CrossFade("falling");
     }
     else if (playerState == GruntState.FallingFromTower)
     {
         m_currentAnimation = "falling";
         if (!m_animation.IsPlaying("falling"))
             m_animation.CrossFade("falling");
     }
 }
Ejemplo n.º 5
0
    public void PushPlayerFromTower()
    {
        if (m_playerState == GruntState.FallingFromTower)
        {
            return;
        }

        m_playerState = GruntState.FallingFromTower;
        m_dead.y      = transform.position.y;
        m_dead.time   = Time.time * 1000.0f;
    }
Ejemplo n.º 6
0
    /*
     * \brief Called when this first collides with something
     */
    void OnCollisionEnter(Collision collision)
    {
        if (m_playerState == GruntState.FallingFromTower)
        {
            return;
        }

        foreach (ContactPoint contact in collision)
        {
            //Debug.Log("This Collider: " + contact.thisCollider.gameObject.name);
            //Debug.Log("Other Collider: " + contact.otherCollider.gameObject.name);
            if (contact.otherCollider != null && contact.otherCollider.gameObject != null)
            {
                if (contact.otherCollider.gameObject.name == "Player Spawn")
                {
                    //Debug.Log("Collided with player");
                    m_playerState = GruntState.Attacking;
                    m_ticksInContactWithPlayer++;
                }
            }
            if (contact.thisCollider.gameObject.name == "Bip001 L Hand001" && contact.otherCollider.gameObject.name == "Player Spawn")
            {
                Debug.Log("Hit player");
                CEntityPlayer.GetInstance().PushPlayerFromTower();
                m_playerDetected = false;
            }
        }


        m_physics.CallOnCollisionEnter(collision, m_playerDetected);

        if (collision.collider.gameObject.name == "GruntBarrier")
        {
            m_onBarrier = true;
        }
        if (collision.collider.gameObject.name == "GruntSpawn" && !m_playerDetected)
        {
            m_playerState             = GruntState.Standing;
            m_physics.MovingDirection = -1;
        }
        if (collision.collider.gameObject.name == "Electricity")
        {
            //Kill grunt
            Object deathBlast = Instantiate(DeathEffect, transform.position, transform.rotation);
            Destroy(deathBlast, 2);
            Debug.Log(this);
            this.transform.gameObject.SetActiveRecursively(false);
        }
    }
Ejemplo n.º 7
0
        /// <summary>
        /// once the grunt is moving, it should move like this
        /// </summary>

        public void move(Player p)
        {
            //if the grunt has spawned then its y location sould change by the grunt jump increment (gruntJI)
            // and jumping is true
            if (isSpawn == true)
            {
                while (location.Y >= gMaxHeight)
                {
                    location.Y -= gruntJI;
                    jumping     = true;
                }

                //if the grunts y location has reached its maximum height
                // then it os no longer jumping and it is falling
                if (location.Y <= gMaxHeight)
                {
                    jumping = false;
                    falling = true;
                }
                //if its is falling then its location decrements by the gruntJumpIncrement
                if (falling == true)
                {
                    while (location.Y <= ground)
                    {
                        location.Y += gruntJI;
                    }
                }
                //if the grunt has reached the ground
                //then it is no longer falling or jumping
                if (location.Y >= ground)
                {
                    jumping = false;
                    falling = false;
                }
                //for an amount of speed, move distance of a few pixels
                if (p.location.X <= location.X)
                {
                    gruntState  = GruntState.WalkRight;
                    location.X -= Speed;
                }
                else if (p.location.X >= location.X)
                {
                    gruntState  = GruntState.WalkLeft;
                    location.X += Speed;
                }
            }
        }
Ejemplo n.º 8
0
    public void CallOnTriggerStay(Collider collider, ref GruntState playerState)
    {
        CSceneObject obj = collider.gameObject.GetComponent <CSceneObject>();

        if (obj == null && collider.gameObject != null && collider.gameObject.transform.parent != null)
        {
            GameObject parent = collider.gameObject.transform.parent.gameObject;
            if (parent != null)
            {
                obj = parent.GetComponent <CSceneObject>();
            }
        }

        if (obj != null && obj.KillPlayerOnTouch)
        {
            //m_grunt.PushPlayerFromTower();
        }
    }
Ejemplo n.º 9
0
    void OnTriggerEnter(Collider collider)
    {
        //Debug.Log (collider.gameObject.name);
        if (collider.gameObject.name == "Ledge_Grab_Detection")
        {
            //Player should be detected now
            if (!m_playerDetected)
            {
                m_playerDetected = true;
                m_animation.PlayAudio(m_animation.PlayerDetected);
            }

            m_resetTimer = Time.time;

            if (!m_onBarrier)
            {
                m_playerState = GruntState.Walking;
            }
        }
    }
Ejemplo n.º 10
0
    /*
     * \brief Called when the object is created. At the start.
     *        Only called once per instaniation.
     */
    public override void Start()
    {
        base.Start();

        if (Application.platform == RuntimePlatform.Android)
        {
            Screen.orientation = ScreenOrientation.Landscape;
        }

        //Time.timeScale = 0.75f;

        m_playerPositionAlpha = InitialAlphaPosition;
        m_name = "Grunt";

        m_physics = GetComponent <CGruntPhysics>();
        m_physics.Create(this, GetComponent <Rigidbody>());

        //m_cameraClass = MainCamera.GetComponent<CCamera>();

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

        m_playerHealth = MaxHealth;

        m_characterMesh          = this.transform.Find("GruntMesh");
        m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y + 90, 0));

        m_physics.MovingDirection = StartFacing == LeftRight.Left ? 1 : -1;

        m_playerState = GruntState.Walking;

        m_dead.didDie = false;


        m_debug = GetComponent <CGruntDebug>();
        if (m_debug != null)
        {
            m_debug.SetPlayer(this);
        }
    }
Ejemplo n.º 11
0
    private bool CanJump(GruntState playerState)
    {
        if (playerState == GruntState.LedgeHang)
        {
            return(false);
        }

        if (playerState == GruntState.LedgeClimb)
        {
            return(false);
        }

        if (playerState == GruntState.LedgeClimbComplete)
        {
            return(false);
        }

        if (m_collisionState != CollisionState.OnFloor)
        {
            return(false);
        }

        return(true);
    }
    /*
     * \brief Called when the object is created. At the start.
     *        Only called once per instaniation.
    */
    public override void Start()
    {
        base.Start();

        if (Application.platform == RuntimePlatform.Android)
            Screen.orientation = ScreenOrientation.Landscape;

        //Time.timeScale = 0.75f;

        m_playerPositionAlpha = InitialAlphaPosition;
        m_name = "Grunt";

        m_physics = GetComponent<CGruntPhysics>();
        m_physics.Create(this, GetComponent<Rigidbody>());

        //m_cameraClass = MainCamera.GetComponent<CCamera>();

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

        m_playerHealth = MaxHealth;

        m_characterMesh = this.transform.Find("GruntMesh");
        m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y + 90, 0));

        m_physics.MovingDirection = StartFacing == LeftRight.Left ? 1 : -1;

        m_playerState = GruntState.Walking;

        m_dead.didDie = false;

        m_debug = GetComponent<CGruntDebug>();
        if (m_debug != null)
        {
            m_debug.SetPlayer(this);
        }
    }
 /*
  * \brief External access to set a players state
 */
 public void SetGruntState(GruntState newState)
 {
     m_playerState = newState;
 }
    public void PushPlayerFromTower()
    {
        if (m_playerState == GruntState.FallingFromTower)
            return;

        m_playerState = GruntState.FallingFromTower;
        m_dead.y = transform.position.y;
        m_dead.time = Time.time * 1000.0f;
    }
    /*
     * \brief Called once per frame
    */
    public override void FixedUpdate()
    {
        if( m_ticksInContactWithPlayer > 1 )
        {
            CEntityPlayer.GetInstance().PushPlayerFromTower();
            m_ticksInContactWithPlayer = 0;
            m_playerDetected = false;
        }
        if( m_playerDetected )
        {
            if(m_resetTimer + TimeToReset < Time.time)
            {
                //reset detection
                m_playerDetected = false;
                m_playerState = GruntState.Turning;
                if( m_physics.MovingDirection == 1)
                {
                    m_physics.MovingDirection = -1;
                    //m_physics.MovingDirection = -1;
                }
                else if( m_physics.MovingDirection == -1 )
                {
                    m_physics.MovingDirection = 1;
                    //m_direction = 1;
                }
            }
        }

        if( m_playerPositionAlpha > 360.0f )
        {
            m_playerPositionAlpha -= 360.0f;
        }
        else if( m_playerPositionAlpha <= -360.0f )
        {
            m_playerPositionAlpha += 360.0f;
        }

        m_lastPlayerPositionAlpha = m_playerPositionAlpha;

        m_physics.OnFixedUpdate(ref m_playerState, m_playerDetected);

        m_playerPositionAlpha -= m_physics.Velocity;
        m_playerPositionAlpha += m_physics.PlatformVelocity;

        m_physics.PlatformVelocity = 0.0f;

        float additionalY = 0.0f;

        if (m_playerState == GruntState.FallingFromTower) {
            m_additionalRadius += (0.025f * m_physics.Invert);
            m_additionalRadius = Mathf.Clamp(m_additionalRadius, -3.0f, 3.0f);
            m_playerPositionAlpha = m_lastPlayerPositionAlpha;
        }

        float yPosition = transform.position.y + additionalY;

        m_position = new Vector3(
            Mathf.Sin(m_playerPositionAlpha * Mathf.Deg2Rad) * (PlayerPathRadius + m_additionalRadius),
            yPosition,
            Mathf.Cos(m_playerPositionAlpha * Mathf.Deg2Rad) * (PlayerPathRadius + m_additionalRadius)
        );

        // Animate and position the player model mesh
        {

            if (m_playerState == GruntState.Turning)
            {
                //Debug.Log("NOT IN ROTATION CODE");
            }
            else
            {
                //Debug.Log("rOTATION");
                if (m_physics.Direction > 0)
                {
                    m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y + 90, 0));
                }
                else if (m_physics.Direction < 0)
                {
                    m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y - 90, 0));
                }
                else if (m_physics.MovingDirection > 0)
                {
                    m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y + 90, 0));
                }
                else if (m_physics.MovingDirection < 0)
                {
                    m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y - 90, 0));
                }
            }

            int mDirection = m_physics.MovingDirection;
            m_animation.OnFixedUpdate(ref m_playerState, ref mDirection, m_physics, m_physics.GetFootMaterial(), m_playerDetected);
            m_physics.MovingDirection = mDirection;
        }

        if (m_playerState == GruntState.FallingFromTower && (Time.time * 1000.0f) - m_dead.time > 3000)
        {
            OnDeath();
        }

        base.FixedUpdate();
    }
    public void CallOnTriggerStay(Collider collider, ref GruntState playerState)
    {
        CSceneObject obj = collider.gameObject.GetComponent<CSceneObject>();
        if (obj == null && collider.gameObject != null && collider.gameObject.transform.parent != null) {
            GameObject parent = collider.gameObject.transform.parent.gameObject;
            if (parent != null) {
                obj = parent.GetComponent<CSceneObject>();
            }
        }

        if (obj != null && obj.KillPlayerOnTouch)
        {
            m_grunt.PushPlayerFromTower();
        }
    }
    /*
     * \brief Called on player update
    */
    public void OnFixedUpdate(ref GruntState playerState, bool playerDetected)
    {
        if (playerState == GruntState.FallingFromTower)
            return;

        GameObject player = GameObject.Find("Player Spawn");
        float playerAlpha = player.GetComponent<CEntityPlayer>().CurrentPlayerAlpha;
        float gruntAlpha = m_grunt.CurrentPlayerAlpha;

        if( playerDetected )
        {
            if( playerAlpha > gruntAlpha + 180 )
            {
                gruntAlpha += 360;
            }
            else if( playerAlpha + 180 < gruntAlpha )
            {
                gruntAlpha -= 360;
            }
            if( playerAlpha > gruntAlpha )
            {
                m_movingDirection = -1;
                m_direction = -1;
            }
            else if ( gruntAlpha > playerAlpha )
            {
                m_movingDirection = 1;
                m_direction = 1;
            }
        }

        //	float velocity = (Input.GetAxis("Horizontal") * MaxSpeed) * m_invert;
        //	if (Application.platform == RuntimePlatform.Android)
        //		velocity = Input.acceleration.y;
        float velocity = 0.0f;
        if( m_movingDirection != 0 )
        {
            if( playerState != GruntState.Turning && playerState != GruntState.Attacking && playerState != GruntState.Standing )
            {
                if(m_grunt.GetGruntPlayerDetected())
                {
                    velocity = (m_movingDirection * DetectedSpeed);
                }
                else
                {
                    velocity = (m_movingDirection * PeacefulSpeed);
                }
            }
        }

        if ((Time.time * 1000.0f) - m_velocityLockTimer < 100)
        {
            velocity = m_velocity;
        }

        int direction = isNearly(velocity, 0.0f, 0.1f) ? 0 : velocity > 0 ? 1 : -1;

        //platform update
        if (m_platform && m_collisionState == CollisionState.OnFloor) {
            m_platformVelocity += m_platform.DeltaA;
            m_platform.resetDeltaA();
        }

        if (!(m_collisionState == CollisionState.OnWall && m_jumpState == JumpState.Jumping))
            m_velocity = velocity;

        if (playerState != GruntState.Turning)
        {
            m_direction = direction;
            if (m_direction != 0) m_movingDirection = m_direction;
        }

        if (m_collisionState != CollisionState.None && m_jumpState != JumpState.Jumping)
        {
            if (m_movingDirection == 0 && playerState != GruntState.Turning)
            {
                //playerState = GruntState.Standing;
            }
            else
            {
                if (playerState == GruntState.Turning)
                {
                    m_velocity = 0.0f;
                    return;
                }
            }

        }
    }
Ejemplo n.º 18
0
 public new void Start()
 {
     base.Start();
     state = GruntState.Moving;
 }
Ejemplo n.º 19
0
    /*
     * \brief Called on player update
     */
    public void OnFixedUpdate(ref GruntState playerState, bool playerDetected)
    {
        if (playerState == GruntState.FallingFromTower)
        {
            return;
        }

        GameObject player      = GameObject.Find("Player Spawn");
        float      playerAlpha = player.GetComponent <CEntityPlayer>().CurrentPlayerAlpha;
        float      gruntAlpha  = m_grunt.CurrentPlayerAlpha;

        if (playerDetected)
        {
            if (playerAlpha > gruntAlpha + 180)
            {
                gruntAlpha += 360;
            }
            else if (playerAlpha + 180 < gruntAlpha)
            {
                gruntAlpha -= 360;
            }
            if (playerAlpha > gruntAlpha)
            {
                m_movingDirection = -1;
                m_direction       = -1;
            }
            else if (gruntAlpha > playerAlpha)
            {
                m_movingDirection = 1;
                m_direction       = 1;
            }
        }

        //	float velocity = (Input.GetAxis("Horizontal") * MaxSpeed) * m_invert;
        //	if (Application.platform == RuntimePlatform.Android)
        //		velocity = Input.acceleration.y;
        float velocity = 0.0f;

        if (m_movingDirection != 0)
        {
            if (playerState != GruntState.Turning && playerState != GruntState.Attacking && playerState != GruntState.Standing)
            {
                if (m_grunt.GetGruntPlayerDetected())
                {
                    velocity = (m_movingDirection * DetectedSpeed);
                }
                else
                {
                    velocity = (m_movingDirection * PeacefulSpeed);
                }
            }
        }

        if ((Time.time * 1000.0f) - m_velocityLockTimer < 100)
        {
            velocity = m_velocity;
        }

        int direction = isNearly(velocity, 0.0f, 0.1f) ? 0 : velocity > 0 ? 1 : -1;

        //platform update
        if (m_platform && m_collisionState == CollisionState.OnFloor)
        {
            m_platformVelocity += m_platform.DeltaA;
            m_platform.resetDeltaA();
        }


        if (!(m_collisionState == CollisionState.OnWall && m_jumpState == JumpState.Jumping))
        {
            m_velocity = velocity;
        }

        if (playerState != GruntState.Turning)
        {
            m_direction = direction;
            if (m_direction != 0)
            {
                m_movingDirection = m_direction;
            }
        }

        if (m_collisionState != CollisionState.None && m_jumpState != JumpState.Jumping)
        {
            if (m_movingDirection == 0 && playerState != GruntState.Turning)
            {
                //playerState = GruntState.Standing;
            }
            else
            {
                if (playerState == GruntState.Turning)
                {
                    m_velocity = 0.0f;
                    return;
                }
            }
        }
    }
 public void OnFixedUpdate(ref GruntState playerState, ref int movingDirection, CGruntPhysics physics, FootMaterial footMaterial, bool isDetected)
 {
     if (playerState == GruntState.Walking)
     {
         if(isDetected)
         {
             m_currentAnimation = "run";
             if (!m_animation.IsPlaying("run"))
             {
                 m_animation.CrossFade("run", 0.2f);
                 PlayFootstepAudio(footMaterial);
             }
         }
         else
         {
             m_currentAnimation = "walk";
             if (!m_animation.IsPlaying("walk"))
             {
                 m_animation.CrossFade("walk", 0.2f);
                 PlayFootstepAudio(footMaterial);
             }
         }
     }
     else if (playerState == GruntState.Turning)
     {
         m_currentAnimation = "walk180turn";
         if (!m_animation.IsPlaying("walk180turn") && !m_startedTurningRound)
         {
             Debug.Log("On turn start");
             m_startedTurningRound = true;
             m_animation["walk180turn"].speed = 1.0f;
             m_animation.CrossFade("walk180turn");
         }
         else if (!m_animation.IsPlaying("walk180turn"))
         {
             m_startedTurningRound = false;
             playerState = GruntState.Walking;
             Debug.Log("On turn complete");
             /*
             if( movingDirection == 1)
             {
                 movingDirection = -1;
             }
             else if( movingDirection == -1 )
             {
                 movingDirection = 1;
             }
             */
         }
     }
     else if (playerState == GruntState.Attacking)
     {
         m_currentAnimation = "alert_attack1";
         if (!m_animation.IsPlaying("alert_attack1") && !m_startedAttacking)
         {
             Debug.Log("On attack start");
             m_startedAttacking = true;
             m_animation["alert_attack1"].speed = 1.0f;
             m_animation.CrossFade("alert_attack1");
             PlayAttackSound();
         }
         else if (!m_animation.IsPlaying("alert_attack1"))
         {
             m_startedAttacking = false;
             playerState = GruntState.Walking;
             Debug.Log("On attack complete");
         }
     }
     else if (playerState == GruntState.Standing)
     {
         if (!m_animation.IsPlaying(m_lastKnownIdle))
         {
             if( isDetected )
             {
                 m_currentAnimation = "alert-idle-" + Random.Range(0, 1);
                 m_animation[m_currentAnimation].speed = 1.0f;
             }
             else
             {
                 m_currentAnimation = "idle-" + Random.Range(0, 2);
                 m_animation[m_currentAnimation].speed = Random.Range(10, 30) / 100.0f;
             }
             m_lastKnownIdle = m_currentAnimation;
             m_animation.CrossFade(m_currentAnimation);
         }
     }
     else if (playerState == GruntState.Jumping)
     {
         m_currentAnimation = "run-jump";
         if (!m_animation.IsPlaying("run-jump"))
             m_animation.Play("run-jump");
     }
     else if (playerState == GruntState.FallJumping)
     {
         m_currentAnimation = "falling";
         if (!m_animation.IsPlaying("falling"))
             m_animation.CrossFade("falling");
     }
     else if (playerState == GruntState.FallingFromTower)
     {
         m_currentAnimation = "falling";
         if (!m_animation.IsPlaying("falling"))
             m_animation.CrossFade("falling");
     }
 }
    /*
     * \brief Called whilst a collision is taking place
    */
    public void CallOnCollisionStay(Collision collision, ref GruntState playerState, ref float playerAlpha)
    {
        m_collisionState = CollisionState.None;

        foreach (ContactPoint contact in collision)
        {
            Debug.DrawRay(contact.point, contact.normal);
            //
            if (contact.otherCollider != null && contact.otherCollider.gameObject != null)
            {
                CSceneObjectPlatform platform = contact.otherCollider.gameObject.GetComponent<CSceneObjectPlatform>();
                if (platform != null && m_platform == null) {
                    m_platform = platform;
                    m_platform.resetDeltaA();
                }
            }

            //
            CSceneObject obj = null;
            if (contact.otherCollider)
            {
                obj = contact.otherCollider.gameObject.GetComponent<CSceneObject>();
                if (obj == null && contact.otherCollider.gameObject.transform.parent != null) {
                    GameObject parent = contact.otherCollider.gameObject.transform.parent.gameObject;
                    if (parent != null) {
                        obj = parent.GetComponent<CSceneObject>();
                    }
                }
            }

            // floor check
            else if (isNearly(contact.normal.y, 1.0f, 0.8f))
            {
                m_collisionState = CollisionState.OnFloor;
                if (!isNearly(contact.normal.y, 1.0f, 0.15f) && collision.contacts.Length == 1)
                {
                    m_velocity = (m_movingDirection * 0.15f);
                    m_velocityLockTimer = (Time.time * 1000.0f);
                }
                if(contact.otherCollider)
                {
                    // are we on a special material?
                    m_footMaterial = FootMaterial.Stone;
                    if (contact.otherCollider.tag == "Wood Object")
                        m_footMaterial = FootMaterial.Wood;
                    else if (contact.otherCollider.tag == "Metal Object")
                        m_footMaterial = FootMaterial.Metal;
                }
            }
            // head check
            else if (isNearly(contact.normal.y, -1.0f, 0.1f))
            {
                m_collisionState = CollisionState.OnRoof;
            }
            // wall check
            else
            {
                if (isFacingCollision(m_movingDirection, m_body.transform.position, contact.point, playerAlpha)) {
                    m_collisionState = CollisionState.OnWall;
                    break;
                }
            }
        }

        if (m_collisionState == CollisionState.OnWall && m_jumpState == JumpState.Jumping && playerState != GruntState.WallJumpStart)
        {
            m_velocity = -(m_movingDirection * 0.15f);
        }

        if (m_collisionState == CollisionState.OnFloor && ((Time.time * 1000.0f) - m_jumpTimer > 200.0f))
        {
            m_jumpState = JumpState.Landed;

            if (m_grunt.GetGruntState() != GruntState.Turning) m_grunt.SetGruntState(GruntState.Standing);
        }
    }
Ejemplo n.º 22
0
/*
 * \brief Called whilst a collision is taking place
 */
    public void CallOnCollisionStay(Collision collision, ref GruntState playerState, ref float playerAlpha)
    {
        m_collisionState = CollisionState.None;

        foreach (ContactPoint contact in collision)
        {
            Debug.DrawRay(contact.point, contact.normal);
            //
            if (contact.otherCollider != null && contact.otherCollider.gameObject != null)
            {
                CSceneObjectPlatform platform = contact.otherCollider.gameObject.GetComponent <CSceneObjectPlatform>();
                if (platform != null && m_platform == null)
                {
                    m_platform = platform;
                    m_platform.resetDeltaA();
                }
            }

            //
            CSceneObject obj = null;
            if (contact.otherCollider)
            {
                obj = contact.otherCollider.gameObject.GetComponent <CSceneObject>();
                if (obj == null && contact.otherCollider.gameObject.transform.parent != null)
                {
                    GameObject parent = contact.otherCollider.gameObject.transform.parent.gameObject;
                    if (parent != null)
                    {
                        obj = parent.GetComponent <CSceneObject>();
                    }
                }
            }

            // floor check
            else if (isNearly(contact.normal.y, 1.0f, 0.8f))
            {
                m_collisionState = CollisionState.OnFloor;
                if (!isNearly(contact.normal.y, 1.0f, 0.15f) && collision.contacts.Length == 1)
                {
                    if (m_grunt.GetGruntState() == GruntState.Walking)
                    {
                        if (m_grunt.GetGruntPlayerDetected())
                        {
                            m_velocity = (m_movingDirection * 0.6f);
                        }
                        else
                        {
                            m_velocity = (m_movingDirection * 0.15f);
                        }
                        m_velocityLockTimer = (Time.time * 1000.0f);
                    }
                }
                if (contact.otherCollider)
                {
                    // are we on a special material?
                    m_footMaterial = FootMaterial.Stone;
                    if (contact.otherCollider.tag == "Wood Object")
                    {
                        m_footMaterial = FootMaterial.Wood;
                    }
                    else if (contact.otherCollider.tag == "Metal Object")
                    {
                        m_footMaterial = FootMaterial.Metal;
                    }
                }
            }
            // head check
            else if (isNearly(contact.normal.y, -1.0f, 0.1f))
            {
                m_collisionState = CollisionState.OnRoof;
            }
            // wall check
            else
            {
                if (isFacingCollision(m_movingDirection, m_body.transform.position, contact.point, playerAlpha))
                {
                    m_collisionState = CollisionState.OnWall;
                    break;
                }
            }
        }

        if (m_collisionState == CollisionState.OnWall && m_jumpState == JumpState.Jumping && playerState != GruntState.WallJumpStart)
        {
            m_velocity = -(m_movingDirection * 0.15f);
        }

        if (m_collisionState == CollisionState.OnFloor && ((Time.time * 1000.0f) - m_jumpTimer > 200.0f))
        {
            m_jumpState = JumpState.Landed;

            if (m_grunt.GetGruntState() != GruntState.Turning)
            {
                m_grunt.SetGruntState(GruntState.Standing);
            }
        }
    }
    private bool CanJump(GruntState playerState)
    {
        if (playerState == GruntState.LedgeHang)
            return false;

        if (playerState == GruntState.LedgeClimb)
            return false;

        if (playerState == GruntState.LedgeClimbComplete)
            return false;

        if (m_collisionState != CollisionState.OnFloor)
            return false;

        return true;
    }
    public void OnUpdate(ref GruntState playerState)
    {
        if (playerState == GruntState.Standing)
            m_body.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;

        m_isJumpDown = false; //= Input.GetButton("Jump");
        //if (Application.platform == RuntimePlatform.Android)
        //	m_isJumpDown = Input.touchCount != 0;

        if (m_isJumpDown && m_jumpState == JumpState.Landed && CanJump(playerState))
        {
            if ((Time.time * 1000.0f) - m_jumpTimer > JumpDelayMS)
            {
                m_jumpTimer = (Time.time * 1000.0f);
                m_body.AddForce(new Vector3(0, PlayerJumpHeight, 0), ForceMode.Impulse);
                m_jumpState = JumpState.Jumping;
                playerState = GruntState.Jumping;
                m_collisionState = CollisionState.None;
            }
        }

        if (m_jumpState == JumpState.Jumping && playerState == GruntState.Jumping)
        {
            if ((Time.time * 1000.0f) - m_jumpTimer > 2000.0f)
            {
                playerState = GruntState.FallJumping;
            }
        }
    }
    /*
     * \brief Called on player update
    */
    public void OnFixedUpdate(ref GruntState playerState)
    {
        if (playerState == GruntState.FallingFromTower)
            return;

        //	float velocity = (Input.GetAxis("Horizontal") * MaxSpeed) * m_invert;
        //	if (Application.platform == RuntimePlatform.Android)
        //		velocity = Input.acceleration.y;
        float velocity = 0.0f;
        if( m_movingDirection != 0 )
        {
            if( playerState != GruntState.Turning )
            {
                velocity = 0.2f * m_movingDirection;
            }
        }

        if ((Time.time * 1000.0f) - m_velocityLockTimer < 100)
        {
            velocity = m_velocity;
        }

        int direction = isNearly(velocity, 0.0f, 0.1f) ? 0 : velocity > 0 ? 1 : -1;

        //platform update
        if (m_platform && m_collisionState == CollisionState.OnFloor) {
            m_platformVelocity += m_platform.DeltaA;
            m_platform.resetDeltaA();
        }

        if (!(m_collisionState == CollisionState.OnWall && m_jumpState == JumpState.Jumping))
            m_velocity = velocity;

        int lastDirection = m_direction;
        int lastMovingDirection = m_movingDirection;

        if (playerState != GruntState.Turning)
        {
            m_direction = direction;
            if (m_direction != 0) m_movingDirection = m_direction;
        }

        if (m_collisionState != CollisionState.None && m_jumpState != JumpState.Jumping)
        {
            if (m_movingDirection == 0 && playerState != GruntState.Turning)
            {
                //playerState = GruntState.Standing;
            }
            else
            {
                if (playerState == GruntState.Turning)
                {
                    m_velocity = 0.0f;
                    return;
                }

                // are we tuning round?
                if (lastDirection != direction && ((Time.time * 1000.0f) - m_turnLockTimer > 1000.0f))
                {
                    playerState = GruntState.Walking;
                    if (m_velocity != 0.0f && lastMovingDirection != m_direction)
                    {
                        playerState = GruntState.Turning;
                        m_velocity = 0.0f;
                        m_turnLockTimer = Time.time * 1000.0f;
                    }
                }
                else
                    playerState = GruntState.Walking;
            }
        }
    }
    /*
     * \brief Called when this first collides with something
    */
    void OnCollisionEnter(Collision collision)
    {
        if (m_playerState == GruntState.FallingFromTower)
            return;

        foreach (ContactPoint contact in collision)
        {
            //Debug.Log("This Collider: " + contact.thisCollider.gameObject.name);
            //Debug.Log("Other Collider: " + contact.otherCollider.gameObject.name);
            if (contact.otherCollider != null && contact.otherCollider.gameObject != null)
            {
                if(contact.otherCollider.gameObject.name == "Player Spawn")
                {
                    //Debug.Log("Collided with player");
                    m_playerState = GruntState.Attacking;
                    m_ticksInContactWithPlayer++;
                }
            }
            if(contact.thisCollider.gameObject.name == "Bip001 L Hand001" && contact.otherCollider.gameObject.name == "Player Spawn")
            {
                Debug.Log("Hit player");
                CEntityPlayer.GetInstance().PushPlayerFromTower();
                m_playerDetected = false;
            }
        }

        m_physics.CallOnCollisionEnter(collision, m_playerDetected);

        if( collision.collider.gameObject.name=="GruntBarrier" )
        {
            m_onBarrier = true;
        }
        if( collision.collider.gameObject.name=="GruntSpawn" && !m_playerDetected )
        {
            m_playerState = GruntState.Standing;
            m_physics.MovingDirection = -1;
        }
        if( collision.collider.gameObject.name == "Electricity" )
        {
            //Kill grunt
            Object deathBlast = Instantiate(DeathEffect, transform.position, transform.rotation);
            Destroy(deathBlast, 2);
            Debug.Log(this);
            this.transform.gameObject.SetActiveRecursively(false);
        }
    }
    void OnTriggerEnter(Collider collider)
    {
        //Debug.Log (collider.gameObject.name);
        if(collider.gameObject.name == "Ledge_Grab_Detection")
        {
            //Player should be detected now
            if(!m_playerDetected)
            {
                m_playerDetected = true;
                m_animation.PlayAudio(m_animation.PlayerDetected);
            }

            m_resetTimer = Time.time;

            if( !m_onBarrier )
            {
                m_playerState = GruntState.Walking;
            }
        }
    }
    public void OnFixedUpdate(ref GruntState playerState, ref int movingDirection, CGruntPhysics physics, FootMaterial footMaterial, bool isDetected)
    {
        if (playerState == GruntState.Walking)
        {
            if (isDetected)
            {
                m_currentAnimation = "run";
                if (!m_animation.IsPlaying("run"))
                {
                    m_animation.CrossFade("run", 0.2f);
                    PlayFootstepAudio(footMaterial);
                }
            }
            else
            {
                m_currentAnimation = "walk";
                if (!m_animation.IsPlaying("walk"))
                {
                    m_animation.CrossFade("walk", 0.2f);
                    PlayFootstepAudio(footMaterial);
                }
            }
        }
        else if (playerState == GruntState.Turning)
        {
            m_currentAnimation = "walk180turn";
            if (!m_animation.IsPlaying("walk180turn") && !m_startedTurningRound)
            {
                Debug.Log("On turn start");
                m_startedTurningRound            = true;
                m_animation["walk180turn"].speed = 1.0f;
                m_animation.CrossFade("walk180turn");
            }
            else if (!m_animation.IsPlaying("walk180turn"))
            {
                m_startedTurningRound = false;
                playerState           = GruntState.Walking;
                Debug.Log("On turn complete");

                /*
                 * if( movingDirection == 1)
                 * {
                 *      movingDirection = -1;
                 * }
                 * else if( movingDirection == -1 )
                 * {
                 *      movingDirection = 1;
                 * }
                 */
            }
        }
        else if (playerState == GruntState.Attacking)
        {
            m_currentAnimation = "alert_attack1";
            if (!m_animation.IsPlaying("alert_attack1") && !m_startedAttacking)
            {
                Debug.Log("On attack start");
                m_startedAttacking = true;
                m_animation["alert_attack1"].speed = 1.0f;
                m_animation.CrossFade("alert_attack1");
                PlayAttackSound();
            }
            else if (!m_animation.IsPlaying("alert_attack1"))
            {
                m_startedAttacking = false;
                playerState        = GruntState.Walking;
                Debug.Log("On attack complete");
            }
        }
        else if (playerState == GruntState.Standing)
        {
            if (!m_animation.IsPlaying(m_lastKnownIdle))
            {
                if (isDetected)
                {
                    m_currentAnimation = "alert-idle-" + Random.Range(0, 1);
                    m_animation[m_currentAnimation].speed = 1.0f;
                }
                else
                {
                    m_currentAnimation = "idle-" + Random.Range(0, 2);
                    m_animation[m_currentAnimation].speed = Random.Range(10, 30) / 100.0f;
                }
                m_lastKnownIdle = m_currentAnimation;
                m_animation.CrossFade(m_currentAnimation);
            }
        }
        else if (playerState == GruntState.Jumping)
        {
            m_currentAnimation = "run-jump";
            if (!m_animation.IsPlaying("run-jump"))
            {
                m_animation.Play("run-jump");
            }
        }
        else if (playerState == GruntState.FallJumping)
        {
            m_currentAnimation = "falling";
            if (!m_animation.IsPlaying("falling"))
            {
                m_animation.CrossFade("falling");
            }
        }
        else if (playerState == GruntState.FallingFromTower)
        {
            m_currentAnimation = "falling";
            if (!m_animation.IsPlaying("falling"))
            {
                m_animation.CrossFade("falling");
            }
        }
    }
Ejemplo n.º 29
0
    /*
     * \brief Called once per frame
     */
    public override void FixedUpdate()
    {
        if (m_ticksInContactWithPlayer > 1)
        {
            CEntityPlayer.GetInstance().PushPlayerFromTower();
            m_ticksInContactWithPlayer = 0;
            m_playerDetected           = false;
        }
        if (m_playerDetected)
        {
            if (m_resetTimer + TimeToReset < Time.time)
            {
                //reset detection
                m_playerDetected = false;
                m_playerState    = GruntState.Turning;
                if (m_physics.MovingDirection == 1)
                {
                    m_physics.MovingDirection = -1;
                    //m_physics.MovingDirection = -1;
                }
                else if (m_physics.MovingDirection == -1)
                {
                    m_physics.MovingDirection = 1;
                    //m_direction = 1;
                }
            }
        }

        if (m_playerPositionAlpha > 360.0f)
        {
            m_playerPositionAlpha -= 360.0f;
        }
        else if (m_playerPositionAlpha <= -360.0f)
        {
            m_playerPositionAlpha += 360.0f;
        }


        m_lastPlayerPositionAlpha = m_playerPositionAlpha;

        m_physics.OnFixedUpdate(ref m_playerState, m_playerDetected);


        m_playerPositionAlpha -= m_physics.Velocity;
        m_playerPositionAlpha += m_physics.PlatformVelocity;

        m_physics.PlatformVelocity = 0.0f;

        float additionalY = 0.0f;

        if (m_playerState == GruntState.FallingFromTower)
        {
            m_additionalRadius   += (0.025f * m_physics.Invert);
            m_additionalRadius    = Mathf.Clamp(m_additionalRadius, -3.0f, 3.0f);
            m_playerPositionAlpha = m_lastPlayerPositionAlpha;
        }

        float yPosition = transform.position.y + additionalY;

        m_position = new Vector3(
            Mathf.Sin(m_playerPositionAlpha * Mathf.Deg2Rad) * (PlayerPathRadius + m_additionalRadius),
            yPosition,
            Mathf.Cos(m_playerPositionAlpha * Mathf.Deg2Rad) * (PlayerPathRadius + m_additionalRadius)
            );

        // Animate and position the player model mesh
        {
            if (m_playerState == GruntState.Turning)
            {
                //Debug.Log("NOT IN ROTATION CODE");
            }
            else
            {
                //Debug.Log("rOTATION");
                if (m_physics.Direction > 0)
                {
                    m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y + 90, 0));
                }
                else if (m_physics.Direction < 0)
                {
                    m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y - 90, 0));
                }
                else if (m_physics.MovingDirection > 0)
                {
                    m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y + 90, 0));
                }
                else if (m_physics.MovingDirection < 0)
                {
                    m_characterMesh.rotation = Quaternion.Euler(new Vector3(0, this.transform.rotation.eulerAngles.y - 90, 0));
                }
            }

            int mDirection = m_physics.MovingDirection;
            m_animation.OnFixedUpdate(ref m_playerState, ref mDirection, m_physics, m_physics.GetFootMaterial(), m_playerDetected);
            m_physics.MovingDirection = mDirection;
        }


        if (m_playerState == GruntState.FallingFromTower && (Time.time * 1000.0f) - m_dead.time > 3000)
        {
            OnDeath();
        }

        base.FixedUpdate();
    }
Ejemplo n.º 30
0
 public void OnFixedUpdate(ref GruntState playerState, CGruntPhysics physics, FootMaterial footMaterial)
 {
     if (playerState == GruntState.Walking)
     {
         m_currentAnimation = "walk";
         if (!m_animation.IsPlaying("walk"))
         {
             m_animation.CrossFade("walk", 0.2f);
             PlayFootstepAudio(footMaterial);
         }
     }
     else if (playerState == GruntState.Turning)
     {
         m_currentAnimation = "running-turn";
         if (!m_animation.IsPlaying("running-turn") && !m_startedTurningRound)
         {
             m_startedTurningRound             = true;
             m_animation["running-turn"].speed = 1.2f;
             m_animation.CrossFade("running-turn");
         }
         else if (!m_animation.IsPlaying("running-turn"))
         {
             m_startedTurningRound = false;
             playerState           = GruntState.Walking;
         }
     }
     else if (playerState == GruntState.Standing)
     {
         if (!m_animation.IsPlaying(m_lastKnownIdle))
         {
             m_currentAnimation = "idle-" + Random.Range(0, 2);
             m_lastKnownIdle    = m_currentAnimation;
             m_animation[m_currentAnimation].speed = Random.Range(10, 30) / 100.0f;
             m_animation.CrossFade(m_currentAnimation);
         }
     }
     else if (playerState == GruntState.Jumping)
     {
         m_currentAnimation = "run-jump";
         if (!m_animation.IsPlaying("run-jump"))
         {
             m_animation.Play("run-jump");
         }
     }
     else if (playerState == GruntState.FallJumping)
     {
         m_currentAnimation = "falling";
         if (!m_animation.IsPlaying("falling"))
         {
             m_animation.CrossFade("falling");
         }
     }
     else if (playerState == GruntState.FallingFromTower)
     {
         m_currentAnimation = "falling";
         if (!m_animation.IsPlaying("falling"))
         {
             m_animation.CrossFade("falling");
         }
     }
 }
Ejemplo n.º 31
0
 /*
  * \brief External access to set a players state
  */
 public void SetGruntState(GruntState newState)
 {
     m_playerState = newState;
 }
 public void CallOnTriggerExit(Collider collider, ref GruntState playerState)
 {
 }
Ejemplo n.º 33
0
 public void CallOnTriggerExit(Collider collider, ref GruntState playerState)
 {
 }
Ejemplo n.º 34
0
    /*
     * \brief Called on player update
     */
    public void OnFixedUpdate(ref GruntState playerState)
    {
        if (playerState == GruntState.FallingFromTower)
        {
            return;
        }

        //	float velocity = (Input.GetAxis("Horizontal") * MaxSpeed) * m_invert;
        //	if (Application.platform == RuntimePlatform.Android)
        //		velocity = Input.acceleration.y;
        float velocity = 0.0f;

        if (m_movingDirection != 0)
        {
            if (playerState != GruntState.Turning)
            {
                velocity = 0.2f * m_movingDirection;
            }
        }

        if ((Time.time * 1000.0f) - m_velocityLockTimer < 100)
        {
            velocity = m_velocity;
        }

        int direction = isNearly(velocity, 0.0f, 0.1f) ? 0 : velocity > 0 ? 1 : -1;

        //platform update
        if (m_platform && m_collisionState == CollisionState.OnFloor)
        {
            m_platformVelocity += m_platform.DeltaA;
            m_platform.resetDeltaA();
        }


        if (!(m_collisionState == CollisionState.OnWall && m_jumpState == JumpState.Jumping))
        {
            m_velocity = velocity;
        }

        int lastDirection       = m_direction;
        int lastMovingDirection = m_movingDirection;

        if (playerState != GruntState.Turning)
        {
            m_direction = direction;
            if (m_direction != 0)
            {
                m_movingDirection = m_direction;
            }
        }

        if (m_collisionState != CollisionState.None && m_jumpState != JumpState.Jumping)
        {
            if (m_movingDirection == 0 && playerState != GruntState.Turning)
            {
                //playerState = GruntState.Standing;
            }
            else
            {
                if (playerState == GruntState.Turning)
                {
                    m_velocity = 0.0f;
                    return;
                }

                // are we tuning round?
                if (lastDirection != direction && ((Time.time * 1000.0f) - m_turnLockTimer > 1000.0f))
                {
                    playerState = GruntState.Walking;
                    if (m_velocity != 0.0f && lastMovingDirection != m_direction)
                    {
                        playerState     = GruntState.Turning;
                        m_velocity      = 0.0f;
                        m_turnLockTimer = Time.time * 1000.0f;
                    }
                }
                else
                {
                    playerState = GruntState.Walking;
                }
            }
        }
    }