private void Tentacle(TentacleState state) { if (state == TentacleState.idle) { if (Input.GetAxis(attackAxis) > 0.5f) { _tentacle.Invoke("Fire", 0.0f); } else { _canMove = true; _canAim = true; } } else if (state == TentacleState.grabbing) { _canMove = false; _canAim = false; } else if (state == TentacleState.holding) { if (Input.GetAxis(attackAxis) > 0.5f) { _tentacle.Invoke("Fire", 0.0f); } else { _canMove = true; _canAim = true; } } this.tentacleState = _tentacle.state; }
void OnCollisionEnter(Collision collision) { if (state == TentacleState.grabbing) { if (collision.gameObject.tag == "Moveable" || collision.gameObject.tag == "Enemy") { holding = collision.gameObject; Rigidbody rigBod = holding.GetComponent <Rigidbody>(); rigBod.isKinematic = true; holding.layer = 9; state = TentacleState.holding; } if (holding.tag == "Enemy") { ParentEnemy enemy = holding.GetComponent <ParentEnemy>(); enemy.isGrabbed = true; } } if (state == TentacleState.holding) { if (collision.gameObject.tag == "Wall") { inWall = true; } } }
// Update is called once per frame void FixedUpdate() { if (Time.time > NextFireBubble) { Attack2(); } if (Time.time > 10) { Attack3(); } if (RTentacleReady && Time.time > RTentacleNF) { RTentacleState = TentacleState.Attack; } else if (!RTentacleReady && Time.time > RTentacleNF && RTentacleState == TentacleState.Stop) { RTentacleState = TentacleState.Reset; ShootingBubble = true; } if (LTentacleReady && Time.time > LTentacleNF) { LTentacleState = TentacleState.Attack; } else if (!LTentacleReady && Time.time > LTentacleNF && LTentacleState == TentacleState.Stop) { LTentacleState = TentacleState.Reset; ShootingBubble = true; } determineTentacleStateAction(RTentacleState, true); determineTentacleStateAction(LTentacleState, false); }
// Update is called once per frame void Update() { if (lineRenderer.enabled) { //disables around corners lineRenderer.SetPosition(0, gameObject.transform.parent.position); Vector3 direction = lineRenderer.GetPosition(1) - lineRenderer.GetPosition(0); float dist = (Vector2.Distance(lineRenderer.GetPosition(1), lineRenderer.GetPosition(0))); //lineRenderer.material.mainTextureScale = new Vector2(dist * 2, 1); if (dist > maxLength) { tentacleState = TentacleState.disabled; lineRenderer.enabled = false; } RaycastHit2D ray = Physics2D.Raycast(lineRenderer.GetPosition(0), direction, dist, mask); if (ray.collider != null) { if (Vector2.Distance(ray.point, lineRenderer.GetPosition(1)) > allowedDiff) { tentacleState = TentacleState.disabled; lineRenderer.enabled = false; } } } }
public virtual void HitFloor(string partName, Collider col) { if (partName != "tip") { return; } isAttacking = false; //先端が床に触れた StartCoroutine(FadeOut()); state = TentacleState.FadeOut; }
void OnCollisionEnter(Collision collision) { if (state == TentacleState.grabbing) { if (collision.gameObject.tag == "Moveable") { holding = collision.gameObject; Rigidbody rigBod = holding.GetComponent <Rigidbody>(); rigBod.isKinematic = true; state = TentacleState.holding; } } }
IEnumerator Attacking() { isAttacking = true; Rigidbody[] bodys = new Rigidbody[others.Length + 1]; float coefficient = 0.5f; bodys[0] = tip.GetComponent <Rigidbody>(); for (int i = 1; i < bodys.Length; i++) { bodys[i] = others[i - 1].GetComponent <Rigidbody>(); } // = tip.GetComponent<Rigidbody>(); WaitForSeconds wait = new WaitForSeconds(0.7f); state = TentacleState.Attack; //倒したい方向を調べる Vector3 targetDirection; Vector3 cross; if (player != null) { targetDirection = Vector3.Normalize(player.transform.position - tip.transform.position); } else { targetDirection = Vector3.Normalize(Vector3.zero - tip.transform.position); } cross = Vector3.Cross(targetDirection, Vector3.up).normalized; coefficient = 0.0f; int patten = 0; while (true) { patten = Random.Range(0, 3); if (patten != 0) { coefficient = Random.Range(-0.5f, 0.5f); AddForce(bodys, cross * Time.deltaTime * powar * coefficient); } else { AddForce(bodys, targetDirection * Time.deltaTime * powar * 2.0f); } yield return(wait); } }
void Fire() { if (state == TentacleState.idle) { state = TentacleState.grabbing; target = _player._aim; //target too far } else if (state == TentacleState.holding) { state = TentacleState.throwing; target = _player._aim; } }
public IEnumerator ExtendTentacle(float time, Vector2 destination) { tentacleState = TentacleState.casting; float elapsedTime = 0; while (elapsedTime < time) { Vector2 position = Vector2.Lerp(lineRenderer.GetPosition(0), destination, (elapsedTime / time)); lineRenderer.SetPosition(1, position); elapsedTime += Time.deltaTime; yield return(null); } tentacleState = TentacleState.extended; }
void Fire() { if (state == TentacleState.idle) { state = TentacleState.grabbing; target = _player._aim; if (Vector3.Distance(target, _player.tentaclePoint.transform.position) > maxRange) { Vector3 direction = GetDirection(target, _player.tentaclePoint.transform.position, maxRange); //Vector3 direction = target - _player.tentaclePoint.transform.position; //direction.Normalize(); //direction *= maxRange; target = _player.tentaclePoint.transform.position + direction; } else if (Vector3.Distance(target, _player.tentaclePoint.transform.position) < minRange) { Vector3 direction = target - _player.tentaclePoint.transform.position; direction.Normalize(); target = _player.tentaclePoint.transform.position + direction; } } else if (state == TentacleState.holding) { state = TentacleState.throwing; target = _player._aim; Rigidbody rigBod = holding.GetComponent <Rigidbody>(); rigBod.isKinematic = false; holding.layer = 0; Vector3 direction = GetDirection(target, _player.transform.position, maxSpeed); rigBod.velocity = direction; if (holding.tag == "Enemy") { ParentEnemy enemy = holding.GetComponent <ParentEnemy>(); enemy.isGrabbed = false; } else { rigBod.mass -= .01f; if (rigBod.mass < .98) { Destroy(holding, 1); } } } }
// Update is called once per frame void Update() { if (state == TentacleState.grabbing) { if (grabCounter != grabDuration / 2) { velocity = target - transform.position; Vector3 pos; pos.x = transform.position.x + velocity.x * Time.deltaTime * 11; pos.y = transform.position.y; pos.z = transform.position.z + velocity.z * Time.deltaTime * 11; transform.position = pos; grabCounter++; if (grabCounter == grabDuration) { transform.position = _player.tentaclePoint.transform.position; grabCounter = 0; state = TentacleState.idle; } } else if (grabCounter == grabDuration / 2) { target = _player.tentaclePoint.transform.position; grabCounter++; } } else if (state == TentacleState.holding) { holding.transform.position = this.transform.position; velocity = _player._aim - transform.position; Vector3 pos; pos.x = transform.position.x + velocity.x * Time.deltaTime * 11; pos.y = transform.position.y; pos.z = transform.position.z + velocity.z * Time.deltaTime * 11; transform.position = pos; } else if (state == TentacleState.throwing) { holding = null; state = TentacleState.idle; } }
float initialAttackDelay; // To allow the scene transition to fade in. One delay for all attack Types // Use this for initialization void Awake() { // INITIAL ATTACK DELAY DIRECTLY BELOW initialAttackDelay = 3.5f; RTentacleRB2D = RightTentacle.GetComponent <Rigidbody2D>(); LTentacleRB2D = LeftTentacle.GetComponent <Rigidbody2D>(); if (this.player == null) { PlayerBehavior temp = FindObjectOfType <PlayerBehavior>(); this.player = temp.gameObject; } LTentacleState = RTentacleState = TentacleState.Stop; RTentacleFR = 7.1f; LTentacleFR = 11.3f; RTentacleNF = Time.time + RTentacleFR + initialAttackDelay; LTentacleNF = Time.time + LTentacleFR + initialAttackDelay; RTentacleReady = LTentacleReady = true; FireIntervalLaser = 12f; FireRateLaser = 0.15f; NextFireLaser = Time.time + FireRateLaser + initialAttackDelay; rand = new System.Random(); Speed = 3f; startAngle = currentAngle = 260; endAngle = 100; Direction = new Vector3(0, 0, 1); pc2D = GetComponent <PolygonCollider2D>(); radius = 15f; fireBubbleTimeBeforeLaser = 6; FireRateBubble = 2f; NextFireBubble = NextFireLaser - fireBubbleTimeBeforeLaser; ShootingBubble = true; }
// Update is called once per frame void Update() { if (state == TentacleState.grabbing) { if (grabCounter != grabDuration / 2) { velocity = GetDirection(target, transform.position, 0); Vector3 pos; pos.x = transform.position.x + velocity.x * Time.deltaTime * 13; pos.y = transform.position.y; pos.z = transform.position.z + velocity.z * Time.deltaTime * 13; transform.position = pos; grabCounter++; if (grabCounter == grabDuration) { transform.position = _player.tentaclePoint.transform.position; grabCounter = 0; state = TentacleState.cooldown; } } else if (grabCounter == grabDuration / 2) { target = _player.tentaclePoint.transform.position; grabCounter++; } } else if (state == TentacleState.holding) { target = _player._aim; //If to far if (Vector3.Distance(target, _player.tentaclePoint.transform.position) > maxRange) { //Max range Vector3 direction = GetDirection(target, _player.tentaclePoint.transform.position, maxRange); target = _player.tentaclePoint.transform.position + direction; } //If to close else if (Vector3.Distance(target, _player.tentaclePoint.transform.position) < 2) { //Min Range 1 Vector3 direction = GetDirection(target, _player.tentaclePoint.transform.position, 2); target = _player.tentaclePoint.transform.position + direction; } if (!inWall) { lastPosition = transform.position; transform.position = target; holding.transform.position = this.transform.position; } else { transform.position = lastPosition; inWall = false; } } else if (state == TentacleState.throwing) { transform.position = _player.tentaclePoint.transform.position; holding = null; state = TentacleState.cooldown; } else if (state == TentacleState.cooldown) { if (cooldownCounter < cooldown) { cooldownCounter++; } else { cooldownCounter = 0; state = TentacleState.idle; } } }
public virtual void Attack() { coroutine = StartCoroutine(Attacking()); state = TentacleState.Attack; }
void determineTentacleStateAction(TentacleState tentacleState, bool right) // right is the right tentacle. if false, it is the left tentacle { if (RightTentacle.transform.rotation.z <= -0.42f && RTentacleState == TentacleState.Attack) { RTentacleState = TentacleState.Stop; RTentacleNF = Time.time + (RTentacleFR / 2.5f); RTentacleReady = false; } if (LeftTentacle.transform.rotation.z >= 0.42f && LTentacleState == TentacleState.Attack) { LTentacleState = TentacleState.Stop; LTentacleNF = Time.time + (LTentacleFR / 2.5f); LTentacleReady = false; } switch (tentacleState) { case TentacleState.Stop: { // Tentacle doesn't move. Can be at either end point if (right && !RTentacleReady) { //RightTentacle.transform.Rotate(new Vector3(0, 0, -55.5f)); } break; } case TentacleState.Attack: { if (right) { RightTentacle.transform.Rotate(Vector3.forward * -Speed * 0.2f); } else { LeftTentacle.transform.Rotate(Vector3.forward * Speed * 0.2f); } break; } case TentacleState.Reset: { if (right) { RightTentacle.transform.Rotate(Vector3.forward * Speed * 0.1f); if (RightTentacle.transform.rotation.z >= 0.0966f) { RTentacleState = TentacleState.Stop; RTentacleReady = true; RTentacleNF = Time.time + RTentacleFR; } } else { LeftTentacle.transform.Rotate(Vector3.forward * -Speed * 0.1f); if (LeftTentacle.transform.rotation.z <= -0.0966f) { LTentacleState = TentacleState.Stop; LTentacleReady = true; LTentacleNF = Time.time + LTentacleFR; } } break; } } }
// Start is called before the first frame update void Start() { lineRenderer = GetComponent <LineRenderer>(); tentacleState = TentacleState.disabled; }