fix player hit

This commit is contained in:
kimura 2022-06-28 14:53:56 +09:00
parent 1ece653773
commit c89df57cc3
2 changed files with 17 additions and 6 deletions

View File

@ -1494,6 +1494,7 @@ MonoBehaviour:
speed: 5
jumpTime: 1.25
jumpHeight: 5
fallTime: 0.5
hitTime: 1.5
hitWaitTime: 1
--- !u!61 &5804782809510212544

View File

@ -10,16 +10,20 @@ namespace MyGame.Scenes.MiniGame.Scripts
[SerializeField] private float speed = 5f;
[SerializeField] private float jumpTime = 1.25f;
[SerializeField] private float jumpHeight = 5f;
[SerializeField] private float fallTime = 1f;
[SerializeField] private float hitTime = 1.5f;
[SerializeField] private float hitWaitTime = 1f;
private bool isJump;
private bool isPreHit;
private readonly BoolReactiveProperty isHit = new BoolReactiveProperty();
private IDisposable hitDisposable;
private Coroutine jumpCoroutine;
private Vector3 basePos;
private void Start()
{
isHit.AddTo(this);
basePos = transform.localPosition;
}
public void Move()
@ -39,10 +43,9 @@ namespace MyGame.Scenes.MiniGame.Scripts
}
isJump = true;
var cachePos = transform.localPosition;
this.CallLerp(jumpTime, t =>
jumpCoroutine = this.CallLerp(jumpTime, t =>
{
transform.SetLocalPositionY(cachePos.y + Mathf.Sin(Mathf.PI * t) * jumpHeight);
transform.SetLocalPositionY(basePos.y + Mathf.Sin(Mathf.PI * t) * jumpHeight);
}, () =>
{
isJump = false;
@ -58,9 +61,16 @@ namespace MyGame.Scenes.MiniGame.Scripts
}
isPreHit = true;
hitDisposable?.Dispose();
// ジャンプが終わるのを待つ
hitDisposable = this.UpdateAsObservable().First(_ => !isJump).Subscribe(_ =>
StopCoroutine(jumpCoroutine);
var diffHeight = transform.localPosition.y - basePos.y;
jumpCoroutine = this.CallLerp(diffHeight == 0f ? 0f : fallTime, t =>
{
var half = 0.5f + t / 2;
transform.SetLocalPositionY(basePos.y + Mathf.Sin(Mathf.PI * half) * diffHeight);
}, () =>
{
isJump = false;
var orgRotation = transform.localRotation;
var orgYAngle = orgRotation.eulerAngles.y;
transform.rotation = Quaternion.identity;
@ -76,7 +86,7 @@ namespace MyGame.Scenes.MiniGame.Scripts
isHit.Value = false;
});
});
}).AddTo(this);
});
}
}
}