示例#1
0
    protected Vector2 MoveTowardsTarget()
    {
        HumanoidState state = GetState();

        if (state == HumanoidState.idle || state == HumanoidState.walk)
        {
            Vector2 direction = ((Vector2)path.vectorPath[currentWaypoint] - myRigidbody.position).normalized;
            Vector2 force     = direction * speed * Time.deltaTime;

            myRigidbody.AddForce(force);

            float distance = Vector2.Distance(myRigidbody.position, path.vectorPath[currentWaypoint]);

            if (distance < nextWaypointDistance)
            {
                currentWaypoint++;
            }

            ChangeState(HumanoidState.walk);

            // returns direction
            return(direction);
        }

        return(Vector3.zero);
    }
示例#2
0
        public void LeaveControl()
        {
            if (this.spaceShip != null)
            {
                this.spaceShip.engineOn = false;
                this.spaceShip.pitchOn  = 0;
                this.spaceShip.rollOn   = 0;
            }

            if (this.lightShip != null)
            {
                this.lightShip.engineOn                = false;
                this.lightShip.pitchOn                 = 0;
                this.lightShip.rollOn                  = 0;
                this.transform.parent                  = this.lightShip.transform.parent;
                this.cRigidbody.isKinematic            = false;
                this.GetComponent <Collider>().enabled = true;
                this.state       = HumanoidState.Stand;
                this.currentGrav = this.transform.parent.GetComponent <Gravity> ();
            }

            this.cRigidbody.isKinematic            = false;
            this.GetComponent <Collider>().enabled = true;

            this.seat               = null;
            this.spaceShip          = null;
            this.lightShip          = null;
            this.head.localRotation = Quaternion.identity;
            this.state              = HumanoidState.Stand;
        }
示例#3
0
    // AWAKE [make references to own objects]
    private void Awake()
    {
        animator    = GetComponent <Animator>();
        myRigidbody = GetComponent <Rigidbody2D>();

        currentState = HumanoidState.idle;
    }
示例#4
0
 // STATE
 protected void ChangeState(HumanoidState newState)
 {
     if (currentState != newState)
     {
         currentState = newState;
     }
 }
示例#5
0
    public int CopyState(int _fromStateId, int _toStateId)
    {
        HumanoidState _fState = savedStates[_fromStateId];

        int boneCount = _fState.pos.Length;
        int nStateID  = _toStateId;

        HumanoidState _cState = savedStates[nStateID];

        _cState.current_accumulative_reward = _fState.current_accumulative_reward;
        _cState.current_step = _fState.current_step;

        for (int i = 0; i < boneCount; i++)
        {
            _cState.pos[i]  = _fState.pos[i];
            _cState.rot[i]  = _fState.rot[i];
            _cState.vel[i]  = _fState.vel[i];
            _cState.aVel[i] = _fState.aVel[i];

            _cState.touchingGround[i] = _fState.touchingGround[i];
            _cState.touchingWall[i]   = _fState.touchingWall[i];

            _cState.touchingHold[i]   = _fState.touchingHold[i];
            _cState.touchingHoldId[i] = _fState.touchingHoldId[i];

            _cState.touchingTarget[i] = _fState.touchingTarget[i];
        }

        return(nStateID);
    }
示例#6
0
    // COMBAT
    public void OnAttack()
    {
        HumanoidState state = GetState();

        if (state != HumanoidState.attack && state != HumanoidState.stagger)
        {
            StartCoroutine(AttackCoroutine());
        }
    }
示例#7
0
    private void UseHands()
    {
        if (anim.GetCurrentAnimatorStateInfo(0).IsName("idle") && leftHand.isUsingHand())
        {
            leftHand.StopUsingHand();
            setStartDirectionPosition();
        }

        if (anim.GetCurrentAnimatorStateInfo(0).IsName("idle") && rightHand.isUsingHand())
        {
            rightHand.StopUsingHand();
            Debug.Log(getAttackDirection());
        }


        if (leftHandInput > 0)
        {
            if (leftHand.GetItemType() == ItemType.MELEE && state == HumanoidState.Combat)
            {
                anim.SetBool("IsPerformingAction", true);
            }
            else if (leftHand.GetItemType() == ItemType.MELEE && state == HumanoidState.Idle)
            {
                state = HumanoidState.Combat;
            }
            leftHand.UseHand();
        }
        else
        {
            anim.SetBool("IsPerformingAction", false);
        }

        if (rightHandInput > 0)
        {
            if (rightHand.GetItemType() == ItemType.MELEE && state == HumanoidState.Combat)
            {
                anim.SetBool("IsPerformingAction", true);
            }
            else if (rightHand.GetItemType() == ItemType.MELEE && state == HumanoidState.Idle)
            {
                state = HumanoidState.Combat;
            }

            rightHand.UseHand();
        }
        else
        {
            anim.SetBool("IsPerformingAction", false);
        }

        if (anim.GetCurrentAnimatorStateInfo(0).IsName("FinishedAction"))
        {
            Debug.Log("InFinishedAction");
            anim.SetBool("IsPerformingAction", false);
            //TODO: This isn't working right, it's not properly getting set to false, I cannot seem to figure out why it seems to be getting set to true again the same process as this sets it to false?
        }
    }
示例#8
0
 public void TakeControl(LightShip lightShip, Transform seat)
 {
     this.seat                              = seat;
     this.lightShip                         = lightShip;
     this.cTransform.parent                 = this.lightShip.transform;
     this.cRigidbody.isKinematic            = true;
     this.GetComponent <Collider>().enabled = false;
     this.state                             = HumanoidState.PilotLightShip;
 }
示例#9
0
    // Update is called once per frame
    private void Update()
    {
        HumanoidState state = GetState();

        if (Input.GetButtonDown("Attack") && state != HumanoidState.attack &&
            state != HumanoidState.stagger)
        {
            StartCoroutine(AttackCoroutine());
        }
    }
示例#10
0
    // Update is called once per frame
    private void Update()
    {
        HumanoidState state = GetState();

        if (Input.GetButtonDown("Attack") && state != HumanoidState.attack &&
            state != HumanoidState.stagger)
        {
            StartCoroutine(AttackCoroutine());
        }

        //for (int i = 0; i < Input.touchCount; i++) {
        //    Vector3 touchPos = Camera.main.ScreenToWorldPoint(Input.touches[i].position);
        //    Debug.DrawLine(transform.position, touchPos, Color.red);
        //}
    }
示例#11
0
    public void Knockback(Vector2 knockVector, float recoverTime)
    {
        HumanoidState state = GetState();

        if (myRigidbody && state != HumanoidState.stagger && !IsDead())
        {
            // set state
            ChangeState(HumanoidState.stagger);

            // add force
            myRigidbody.AddForce(knockVector, ForceMode2D.Impulse);

            // recover
            StartCoroutine(RecoverCoroutine(recoverTime));
        }
    }
示例#12
0
    // FixedUpdate is called when physics update
    private void FixedUpdate()
    {
        // reset change
        moveChange = Vector3.zero;

        // get new change
        moveChange.x = Input.GetAxisRaw("Horizontal");
        moveChange.y = Input.GetAxisRaw("Vertical");

        HumanoidState state = GetState();

        if (state == HumanoidState.walk || state == HumanoidState.idle)
        {
            // move character
            UpdateAnimationAndMove();
        }
    }
示例#13
0
        //double xpos = 0;
        ///double ypos = 1;
        //double zpos = 0;

        /// <summary>
        /// Service start
        /// </summary>
        protected override void Start()
        {
            //
            // Add service specific initialization here
            //

            base.Start();


            SetupCamera();

            // Add objects (entities) in our simulated world
            PopulateWorld();

            if (_state == null)
            {
                _state = new HumanoidState();
            }

            SaveState(_state);
        }
示例#14
0
		public void TakeControl (SpaceShip spaceShip, Transform seat) {
			this.seat = seat;
			this.spaceShip = spaceShip;
			this.state = HumanoidState.PilotMotherShip;
		}
示例#15
0
 public void TakeControl(SpaceShip spaceShip, Transform seat)
 {
     this.seat      = seat;
     this.spaceShip = spaceShip;
     this.state     = HumanoidState.PilotMotherShip;
 }
示例#16
0
		public void TakeControl (LightShip lightShip, Transform seat) {
			this.seat = seat;
			this.lightShip = lightShip;
			this.cTransform.parent = this.lightShip.transform;
			this.cRigidbody.isKinematic = true;
			this.GetComponent<Collider>().enabled = false;
			this.state = HumanoidState.PilotLightShip;
		}
示例#17
0
		public void LeaveControl () {
			if (this.spaceShip != null) {
				this.spaceShip.engineOn = false;
				this.spaceShip.pitchOn = 0;
				this.spaceShip.rollOn = 0;
			}

			if (this.lightShip != null) {
				this.lightShip.engineOn = false;
				this.lightShip.pitchOn = 0;
				this.lightShip.rollOn = 0;
				this.transform.parent = this.lightShip.transform.parent;
				this.cRigidbody.isKinematic = false;
				this.GetComponent<Collider>().enabled = true;
				this.state = HumanoidState.Stand;
				this.currentGrav = this.transform.parent.GetComponent<Gravity> ();
			}

			this.cRigidbody.isKinematic = false;
			this.GetComponent<Collider>().enabled = true;

			this.seat = null;
			this.spaceShip = null;
			this.lightShip = null;
			this.head.localRotation = Quaternion.identity;
			this.state = HumanoidState.Stand;
		}