Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void OnTriggerEnter2D(Collider2D other)
- {
- Debug.Log("OnTriggerEnter2D");
- PlayerController player = other.GetComponent<PlayerController>();
- if (player && !_isPlayerOnMe)
- {
- _isPlayerOnMe = true;
- player.Cling(new Vector2(transform.position.x, transform.position.y));
- }
- }
- public void Cling(Vector2 position)
- {
- StartCoroutine(AdjustPosition(position));
- }
- private IEnumerator AdjustPosition(Vector2 position)
- {
- while (Vector2.Distance(_rb.position, position) > 0.01)
- {
- _rb.MovePosition(position);
- yield return new WaitForFixedUpdate();
- }
- _rb.bodyType = RigidbodyType2D.Static;
- yield return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement