public virtual void DoUpdate() { #if UNITY_EDITOR if (!Application.isPlaying) { return; } #endif if (GameManager.isInSceneTransition || GameManager.paused) { return; } HandleSetFacing(); Vector2 moveVector = (facingVector.normalized * moveSpeed * Time.deltaTime) + (rigid.velocity * Time.deltaTime); Physics2D.queriesStartInColliders = true; Collider2D hit = Physics2D.OverlapPoint(GetHeadPosition() + moveVector, whatICrashInto); SetLength(); if (hit == null) { Move(); } else { for (int i = 0; i < verticies.Count; i++) { line.SetPosition(i, verticies[i]); } Breakable breakTile = hit.GetComponent <Breakable>(); if (breakTile != null) { breakTile.OnCollisionEnter2D(null); } else { Hazard hazard = hit.GetComponent <Hazard>(); if (hazard != null) { hazard.OnCollisionEnter2D(null); } } StartCoroutine(sparkCreator.CreateSparkRoutine(GetHeadPosition() + moveVector)); } MakeRipples(); if (IsStuck()) { Gravity(stuckGravity); } else { Gravity(airGravity); } }
public virtual void Gravity(float gravity) { Physics2D.queriesStartInColliders = false; float distFromGround = Mathf.Infinity; RaycastHit2D hit; for (int i = 0; i < verticies.Count; i++) { Vector2 vertexPosition = GetVertexPosition(i); hit = Physics2D.Linecast(vertexPosition, vertexPosition + (Vector2.down * gravity * Time.deltaTime), whatICrashInto); if (hit.collider != null) { float checkDistFromGround = vertexPosition.y - hit.point.y; if (checkDistFromGround >= 0 && checkDistFromGround < distFromGround) { distFromGround = checkDistFromGround; } Breakable breakTile = hit.collider.GetComponent <Breakable>(); if (breakTile != null) { breakTile.OnCollisionEnter2D(null); } else { Hazard hazard = hit.collider.GetComponent <Hazard>(); if (hazard != null) { hazard.OnCollisionEnter2D(null); } } StartCoroutine(sparkCreator.CreateSparkRoutine(hit.point)); } } if (distFromGround == Mathf.Infinity) { trs.position += Vector3.down * gravity * Time.deltaTime; if (!LevelMap.boundsRect.Contains(GetHeadPosition()) && !LevelMap.boundsRect.Contains(GetTailPosition())) { Level.instance.Restart(); } } else { trs.position += Vector3.down * distFromGround; trs.position += Vector3.up * (Physics2D.defaultContactOffset + floatAmount); } }