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); }
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; }
// AWAKE [make references to own objects] private void Awake() { animator = GetComponent <Animator>(); myRigidbody = GetComponent <Rigidbody2D>(); currentState = HumanoidState.idle; }
// STATE protected void ChangeState(HumanoidState newState) { if (currentState != newState) { currentState = newState; } }
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); }
// COMBAT public void OnAttack() { HumanoidState state = GetState(); if (state != HumanoidState.attack && state != HumanoidState.stagger) { StartCoroutine(AttackCoroutine()); } }
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? } }
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; }
// Update is called once per frame private void Update() { HumanoidState state = GetState(); if (Input.GetButtonDown("Attack") && state != HumanoidState.attack && state != HumanoidState.stagger) { StartCoroutine(AttackCoroutine()); } }
// 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); //} }
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)); } }
// 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(); } }
//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); }
public void TakeControl (SpaceShip spaceShip, Transform seat) { this.seat = seat; this.spaceShip = spaceShip; this.state = HumanoidState.PilotMotherShip; }
public void TakeControl(SpaceShip spaceShip, Transform seat) { this.seat = seat; this.spaceShip = spaceShip; this.state = HumanoidState.PilotMotherShip; }
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; }
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; }