void OnCollisionEnter(Collision hit)
 {
     if (hit.gameObject.tag == "walkable")
     {
         this.Ground = GroundState.Grounded;
     }
 }
 // Detect collision exit with floor
 void OnCollisionExit(Collision hit)
 {
     if (hit.gameObject.tag == "walkable")
     {
         this.Ground = GroundState.None;
     }
 }
Exemplo n.º 3
0
    void Start()
    {
        //Create an object to check if player is grounded or touching wall
        groundState  = new GroundState(transform.gameObject);
        gravityStore = GetComponent <Rigidbody2D>().gravityScale;
        anim         = GetComponent <Animator>();
        if (PlayerPrefs.HasKey("VolumeFX"))
        {
            GetComponent <AudioSource>().volume = PlayerPrefs.GetFloat("VolumeFX");
        }


        if (PlayerPrefs.HasKey("Quality"))
        {
            switch (PlayerPrefs.GetInt("Quality"))
            {
            case 2:
                break;

            case 1:
                Camera.main.GetComponent <Bloom>().quality            = 0;
                Camera.main.GetComponent <CameraMotionBlur>().enabled = false;
                break;

            case 0:
                Camera.main.GetComponent <Bloom>().enabled            = false;
                Camera.main.GetComponent <CameraMotionBlur>().enabled = false;
                break;
            }
        }
    }
Exemplo n.º 4
0
        public void UpdateGroundState(GroundState state, bool updateTransparency)
        {
            Color color = Color.red;

            switch (state)
            {
            case GroundState.Buildable:
                UpdateFbxAlpha(0.5f, updateTransparency);
                _groundStateFbx.gameObject.SetActive(true);
                color = Color.green;
                break;

            case GroundState.NotBuildable:
                UpdateFbxAlpha(0.5f, updateTransparency);
                _groundStateFbx.gameObject.SetActive(true);
                color = Color.red;
                break;

            case GroundState.Selected:
                UpdateFbxAlpha(1f, updateTransparency);
                _buildingHeaderUI.gameObject.SetActive(true);
                _groundStateFbx.gameObject.SetActive(true);
                color = Color.yellow;
                break;

            case GroundState.None:
                UpdateFbxAlpha(1f, updateTransparency);
                _buildingHeaderUI.gameObject.SetActive(false);
                _groundStateFbx.gameObject.SetActive(false);
                break;
            }

            _groundStateFbx.material.color = color;
        }
Exemplo n.º 5
0
 private void Initialize()
 {
     // Set initial states.
     _groundState   = new GroundState.OnGroundState(this);
     _actionState   = new ActionState.WalkState(this);
     _cooldownState = new CooldownState.ReadyState(this);
 }
Exemplo n.º 6
0
 public void InAir()
 {
     if (groundState == GroundState.Grounded)
     {
         groundState = GroundState.Falling;
     }
 }
Exemplo n.º 7
0
 private void OnTriggerExit2D(Collider2D collision)
 {
     if (collision.tag == "Ground")
     {
         groundState = GroundState.InAir;
     }
 }
Exemplo n.º 8
0
 void Start()
 {
     audioManager = FindObjectOfType <AudioManager> ();
     rb           = GetComponent <Rigidbody2D> ();
     groundState  = new GroundState(transform.gameObject);
     shake        = GameObject.FindGameObjectWithTag("ScreenShake").GetComponent <Shake> ();
     matDefault   = gfx.GetComponent <SpriteRenderer> ().material;
 }
Exemplo n.º 9
0
    void Start()
    {
        //Create an object to check if player is grounded or touching wall
        groundState = new GroundState(transform.gameObject);
        ourBody     = GetComponent <Rigidbody2D>();

        deathheight = Camera.main.transform.position.y - Camera.main.orthographicSize;
    }
Exemplo n.º 10
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "Ground")
     {
         groundState     = GroundState.onGround;
         rbody.velocity /= 5;
     }
 }
    // Use this for initialization
    void Start()
    {
        rb2d   = GetComponent<Rigidbody2D>();
        anim   = GetComponent<Animator>();
        sprite = GetComponent<SpriteRenderer> ();

        state  = new GroundState (transform.gameObject);
        input.x = 0;
    }
Exemplo n.º 12
0
    private GroundState()
    {
        if (_instance != null)
        {
            return;
        }

        _instance = this;
    }
Exemplo n.º 13
0
    void Start()
    {
        //Create an object to check if player is grounded or touching wall
        groundState = new GroundState(transform.gameObject);

        SpawnPoint   = GameObject.FindWithTag("SpawnPoint");
        InitialScale = transform.localScale;
        touching     = false;
    }
Exemplo n.º 14
0
        void SetGrounded(bool state)
        {
            if (Grounded != state)
            {
                GroundState?.Invoke(state);
            }

            Grounded = state;
        }
Exemplo n.º 15
0
    void Start()
    {
        target      = GameObject.FindWithTag("Player").transform;
        groundState = new GroundState(transform.gameObject);
        seeker      = GetComponent <Seeker>();
        rb          = GetComponent <Rigidbody2D>();
        shake       = GameObject.FindGameObjectWithTag("ScreenShake").GetComponent <Shake>();

        InvokeRepeating("UpdatePath", 0f, .5f);
    }
        private void CGF_OnApplyCGFEvent(CGF cgf, Rigidbody rigid, Collider coll, Vector3 force)
        {
            this.Gravity      = force;
            this.SinceGravity = 0;

            if (this.Ground == GroundState.None)
            {
                this.Ground = GroundState.Falling;
            }
        }
Exemplo n.º 17
0
 void Start()
 {
     //Create an object to check if player is grounded or touching wall
     groundState = new GroundState(transform.gameObject);
     //audio = GetComponent<AudioSource> ();
     //audio.loop = true;
     seen         = false;
     SpawnPoint   = GameObject.FindWithTag("SpawnPoint");
     InitialScale = transform.localScale;
     touching     = false;
 }
Exemplo n.º 18
0
 public void SetState (GroundState newState)
 {
     if (newState == GroundState.Dirt) {
         renderer.material = dirtMaterial;
     } else if (newState == GroundState.Grass) {
         renderer.material = grassMaterial;
     } else if (newState == GroundState.Soil) {
         renderer.material = soilMaterial;
     }
     curState = newState;
 }
Exemplo n.º 19
0
    private float groundTime = 0;                  //time we were last grounded

    void Start()
    {
        //Inizialization
        groundState    = new GroundState(transform, offset, neutralWallMask);
        rb             = GetComponent <Rigidbody2D>();
        playerAnimator = GetComponent <Animator>();

        initColor(colorState);

        Input.ResetInputAxes();
    }
Exemplo n.º 20
0
    private void Update()
    {
        xInput          = Input.GetAxisRaw("Horizontal");
        yInput          = Input.GetAxisRaw("Vertical");
        isHoldingCrouch = Input.GetAxisRaw("Horizontal") < 0 ? true : false;
        isJumpPressed   = Input.GetKeyDown(KeyCode.K);
        isAttackPressed = Input.GetKeyDown(KeyCode.J);


        // Check state and facing direction.
        if (IsCheckerTouchingLayer(lowerGroundCheck, groundLayer))
        {
            if (IsCheckerTouchingLayer(groundCheck, groundLayer))
            {
                groundState = GroundState.OnTheGround;
            }
            else
            {
                groundState = GroundState.InTheAir;
            }
        }
        else
        {
            if (IsCheckerTouchingLayer(groundCheck, shelfLayer))
            {
                groundState = GroundState.OverTheShelf;
            }
            else if (IsCheckerTouchingLayer(ceilingCheck, shelfLayer))
            {
                groundState = GroundState.UnderTheShelf;
            }
            else
            {
                if (IsCheckerTouchingLayer(leftWallCheck, wallLayer))
                {
                    groundState   = GroundState.OnTheWall;
                    isFacingRight = false;
                }
                else if (IsCheckerTouchingLayer(rightWallCheck, wallLayer))
                {
                    groundState   = GroundState.OnTheWall;
                    isFacingRight = true;
                }
                else
                {
                    groundState = GroundState.InTheAir;
                }
            }
        }

        // Check flip
        CheckFlip();
    }
Exemplo n.º 21
0
 private void Motion(Transform start, Transform end, float time, Ease ease, string eventToBroadcastAfterComplete, GroundState stateToSetAfterComplete)
 {
     transform.position = start.position;
     transform.DOMove(end.position, time)
     .SetEase(ease)
     .SetId(MakeUniqueId(GroundMotionTweenId))
     .OnComplete(() =>
     {
         GameMessenger.Broadcast(eventToBroadcastAfterComplete);
         State = stateToSetAfterComplete;
     });
 }
Exemplo n.º 22
0
 void Start()
 {
     audioManager = FindObjectOfType <AudioManager> ();
     //Create an object to check if player is grounded or touching wall
     groundState = new GroundState(transform.gameObject);
     dashTime    = startDashTime;
     //grappling
     joint         = GetComponent <DistanceJoint2D> ();
     joint.enabled = false;
     line.enabled  = false;
     facing        = 1;
     shake         = GameObject.FindGameObjectWithTag("ScreenShake").GetComponent <Shake> ();
     //dash
 }
Exemplo n.º 23
0
 private void Awake()
 {
     if (GetComponent <SpriteRenderer>().material == null)
     {
         GetComponent <SpriteRenderer>().material = material;
     }
     PlayerState = new PlayerState();
     PlayerState = PlayerState.waiting;
     GroundState = new GroundState();
     FrontState  = new FrontState();
     JumpState   = new JumpState();
     TeamID      = -1;
     Hp          = 3;
 }
Exemplo n.º 24
0
        private void Awake()
        {
            rigidbody = GetComponent <Rigidbody2D>();
            collider  = GetComponent <Collider2D>();
            animator  = GetComponent <Animator>();


            stateMachine = ScriptableObject.CreateInstance <StateMachine>();
            groundState  = new GroundState(this);
            ladderState  = new LadderState(this);
            jumpState    = new JumpState(this);
            dieState     = new DieState(this);

            stateMachine.ChangeState(groundState);
        }
Exemplo n.º 25
0
 public void SetState(GroundState newState)
 {
     if (newState == GroundState.Dirt)
     {
         renderer.material = dirtMaterial;
     }
     else if (newState == GroundState.Grass)
     {
         renderer.material = grassMaterial;
     }
     else if (newState == GroundState.Soil)
     {
         renderer.material = soilMaterial;
     }
     curState = newState;
 }
        void onStateChanged(CharacterStateBase newState, CharacterStateBase prevState)
        {
            if (typeof(InAirState).IsAssignableFrom(prevState.GetType()) && typeof(GroundState).IsAssignableFrom(newState.GetType()))
            {
                InAirState inAirState = (InAirState)prevState;

                if (Mathf.Abs(inAirState.LastInAirVelocity.y) > minYVelocityToAnimateLanding)
                {
                    headAnimationController.AnimateLand();
                }
            }

            if (typeof(WallRunState).IsAssignableFrom(newState.GetType()))
            {
                WallRunState wallRunState = (WallRunState)newState;

                switch (wallRunState.WallRunSide)
                {
                case WallRunState.WallRunType.LEFT:

                    spineAnimationController.AnimateWallRunLeft();

                    break;

                case WallRunState.WallRunType.RIGH:

                    spineAnimationController.AnimateWallRunRight();

                    break;
                }
            }

            if (typeof(WallRunState).IsAssignableFrom(prevState.GetType()))
            {
                spineAnimationController.AnimateToDefaultPosition();
            }
            else if (typeof(GroundState).IsAssignableFrom(newState.GetType()))
            {
                GroundState groundState = (GroundState)newState;
                onGroundStateInternalStateChaged(groundState.InternalState);
            }
            else if (typeof(SlideState).IsAssignableFrom(newState.GetType()))
            {
                headAnimationController.SetCrouch(true);
            }
        }
    void Start()
    {
        canMove = true;

        rb       = GetComponent <Rigidbody2D>();
        boxColl  = GetComponent <BoxCollider2D>();
        trail    = GetComponent <TrailRenderer>();
        particle = GetComponent <ParticleSystem>();
        rend     = GetComponent <SpriteRenderer>();
        source   = GetComponent <AudioSource>();
        particle.Stop();
        currentSprite = sprite[0];
        winloseText.SetActive(false);
        groundState = new GroundState(transform.gameObject);
        randomIndex = Random.Range(0, spawnLocation.Length);
        GameObject item = Instantiate(Resources.Load("Prefabs/Collectible"), spawnLocation[randomIndex].transform.position, spawnLocation[randomIndex].transform.rotation) as GameObject;
    }
Exemplo n.º 28
0
 void Start()
 {
     overworldController = GetComponent <OverworldController>();
     //get the rigidbody component
     rb = GetComponent <Rigidbody2D>();
     //create a ground state class
     groundState = new GroundState(transform.gameObject, jumpLayer);
     //turn the sprite to face the player in the chosen direction
     if (!charFacingLeft)
     {
         transform.localRotation = Quaternion.Euler(0, 180, 0);
     }
     //update the sprite direction control bool
     spriteFacingLeft = charFacingLeft;
     upToEnter        = GameObject.Find("Up To Enter");
     upToEnter.SetActive(false);
 }
Exemplo n.º 29
0
 void Start()
 {
     levelController = GetComponent <LevelController>();
     //get the rigidbody component
     rb = GetComponent <Rigidbody2D>();
     //create a ground state class
     groundState = new GroundState(transform.gameObject, jumpLayer);
     //turn the sprite to face the player in the chosen direction
     if (!charFacingLeft)
     {
         transform.localRotation = Quaternion.Euler(0, 180, 0);
     }
     //update the sprite direction control bool
     spriteFacingLeft = charFacingLeft;
     //set the default respawn point as the spawning point
     mapStartPoint = transform.position;
     respawnPoint  = mapStartPoint;
 }
Exemplo n.º 30
0
    private void IdentifyGround()
    {
        if (currentGround.transform.CompareTag("StairObject"))
        {
            cGS = GroundState.ClimbingStairs;
            return;
        }

        if (currentGround.transform.CompareTag("RoughTerrain"))
        {
            cGS = GroundState.RoughTerrain;
            return;
        }



        cGS = GroundState.General;
        return;
    }
Exemplo n.º 31
0
    public virtual void setState(GroundState gs)
    {
        foreach (Transform child in transform)
        {
            child.gameObject.SetActive(false);
        }

        state = gs;

        if (gs == GroundState.Planted)
        {
            var planted = transform.Find("Planted");
            planted.gameObject.SetActive(true);
        }
        if (gs == GroundState.Tilled)
        {
            var tilled = transform.Find("Tilled");
            tilled.gameObject.SetActive(true);
        }
    }
Exemplo n.º 32
0
        //private void OnTriggerEnter2D(Collider2D arg_collider) {
        //	if(arg_collider.gameObject.layer == LayerMask.NameToLayer("Ground")
        //		|| arg_collider.gameObject.layer == LayerMask.NameToLayer("Landable")) {
        //		m_noticeTarget.SendMessage("OnGroundEnter");
        //	}
        //}

        //private void OnTriggerExit2D(Collider2D arg_collider) {

        //	Debug.Log(arg_collider.gameObject.name);

        //	if(!Physics2D.IsTouchingLayers(m_collider , 1 << LayerMask.NameToLayer("Ground"))) {
        //		if (arg_collider.gameObject.layer == LayerMask.NameToLayer("Ground")
        //			|| arg_collider.gameObject.layer == LayerMask.NameToLayer("Landable")) {
        //			m_noticeTarget.SendMessage("OnGroundExit");
        //		}
        //	}
        //}


        private void FixedUpdate()
        {
            RaycastHit2D hitInfo = Physics2D.BoxCast(
                transform.position, m_collider.bounds.size,
                0, Vector2.zero, 0, 1 << LayerMask.NameToLayer("Ground") | 1 << LayerMask.NameToLayer("Landable"));

            GroundState prevState;

            prevState = (hitInfo) ? GroundState.GROUND : GroundState.AIR;

            if (m_currentGroundState != prevState)
            {
                m_currentGroundState = prevState;
                switch (m_currentGroundState)
                {
                case GroundState.GROUND: m_noticeTarget.SendMessage("OnGroundEnter"); break;

                case GroundState.AIR: m_noticeTarget.SendMessage("OnGroundExit"); break;
                }
            }
        }
Exemplo n.º 33
0
    void Start()
    {
        //Create an object to check if player is grounded or touching wall
        groundState = new GroundState(transform.gameObject);

        SpawnPoint = GameObject.FindWithTag ("SpawnPoint");
        InitialScale = transform.localScale;
        touching = false;
    }
Exemplo n.º 34
0
 void Start()
 {
     //Create an object to check if player is grounded or touching wall
     groundState = new GroundState(transform.gameObject);
     //audio = GetComponent<AudioSource> ();
     //audio.loop = true;
     seen = false;
     SpawnPoint = GameObject.FindWithTag ("SpawnPoint");
     InitialScale = transform.localScale;
     touching = false;
 }
Exemplo n.º 35
0
 private void Initialize()
 {
     // Set initial states.
     _groundState   = new GroundState.OnGroundState (this);
     _actionState   = new ActionState.WalkState (this);
     _cooldownState = new CooldownState.ReadyState (this);
 }
Exemplo n.º 36
-2
    protected virtual void Awake()
    {
        m_hForward = false;
        m_hBackward = false;
        m_hRight = false;
        m_hLeft = false;

        m_hWheels = new List<Wheel>();
        m_hRigidbody = this.GetComponent<Rigidbody>();
        m_hRigidbody.interpolation = RigidbodyInterpolation.None;
        //Initialize effective wheels
        List<Transform> gfxPos = this.GetComponentsInChildren<Transform>().Where(hT => hT.GetComponent<WheelCollider>() == null).ToList();
        this.GetComponentsInChildren<WheelCollider>().ToList().ForEach(hW => m_hWheels.Add(new Wheel(hW, gfxPos.OrderBy(hP => Vector3.Distance(hP.position, hW.transform.position)).First().gameObject)));
        m_hWheels = m_hWheels.OrderByDescending(hW => hW.Collider.transform.localPosition.z).ToList();

        //Initialize extra wheels
        m_hFakeWheels = GetComponentsInChildren<FakeWheel>().ToList();

        //Initialize VehicleTurret
        m_hTurret = GetComponentInChildren<VehicleTurret>();

        //Initialize IWeapon
        m_hCurrentWeapon = GetComponentInChildren<IWeapon>();

        m_hActor = GetComponent<Actor>();

        //Initialize Drive/Brake System
        switch (DriveType)
        {
            case DriveType.AWD:
                m_hEngine = new AwdDrive(Hp, m_hWheels);
                break;
            case DriveType.RWD:
                m_hEngine = new RearDrive(Hp, m_hWheels);
                break;
            case DriveType.FWD:
                m_hEngine = new ForwardDrive(Hp, m_hWheels);
                break;
            default:
                break;
        }


        m_hConstanForce = this.GetComponent<ConstantForce>();
        m_hReverseCOM = new Vector3(0.0f, -2.0f, 0.0f);

        m_hOriginalCOM = m_hRigidbody.centerOfMass;


        GroundState hGroundState = new GroundState(this);
        FlyState hFlyState = new FlyState(this);
        TurnedState hTurned = new TurnedState(this, m_hReverseCOM);

        hGroundState.Next = hFlyState;
        hFlyState.Grounded = hGroundState;
        hFlyState.Turned = hTurned;
        hTurned.Next = hFlyState;
        m_hFlyState = hFlyState;
    }