fix player hit
This commit is contained in:
parent
1ece653773
commit
c89df57cc3
|
|
@ -1494,6 +1494,7 @@ MonoBehaviour:
|
||||||
speed: 5
|
speed: 5
|
||||||
jumpTime: 1.25
|
jumpTime: 1.25
|
||||||
jumpHeight: 5
|
jumpHeight: 5
|
||||||
|
fallTime: 0.5
|
||||||
hitTime: 1.5
|
hitTime: 1.5
|
||||||
hitWaitTime: 1
|
hitWaitTime: 1
|
||||||
--- !u!61 &5804782809510212544
|
--- !u!61 &5804782809510212544
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,20 @@ namespace MyGame.Scenes.MiniGame.Scripts
|
||||||
[SerializeField] private float speed = 5f;
|
[SerializeField] private float speed = 5f;
|
||||||
[SerializeField] private float jumpTime = 1.25f;
|
[SerializeField] private float jumpTime = 1.25f;
|
||||||
[SerializeField] private float jumpHeight = 5f;
|
[SerializeField] private float jumpHeight = 5f;
|
||||||
|
[SerializeField] private float fallTime = 1f;
|
||||||
[SerializeField] private float hitTime = 1.5f;
|
[SerializeField] private float hitTime = 1.5f;
|
||||||
[SerializeField] private float hitWaitTime = 1f;
|
[SerializeField] private float hitWaitTime = 1f;
|
||||||
private bool isJump;
|
private bool isJump;
|
||||||
private bool isPreHit;
|
private bool isPreHit;
|
||||||
private readonly BoolReactiveProperty isHit = new BoolReactiveProperty();
|
private readonly BoolReactiveProperty isHit = new BoolReactiveProperty();
|
||||||
private IDisposable hitDisposable;
|
private IDisposable hitDisposable;
|
||||||
|
private Coroutine jumpCoroutine;
|
||||||
|
private Vector3 basePos;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
isHit.AddTo(this);
|
isHit.AddTo(this);
|
||||||
|
basePos = transform.localPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Move()
|
public void Move()
|
||||||
|
|
@ -39,10 +43,9 @@ namespace MyGame.Scenes.MiniGame.Scripts
|
||||||
}
|
}
|
||||||
|
|
||||||
isJump = true;
|
isJump = true;
|
||||||
var cachePos = transform.localPosition;
|
jumpCoroutine = this.CallLerp(jumpTime, t =>
|
||||||
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;
|
isJump = false;
|
||||||
|
|
@ -58,9 +61,16 @@ namespace MyGame.Scenes.MiniGame.Scripts
|
||||||
}
|
}
|
||||||
isPreHit = true;
|
isPreHit = true;
|
||||||
hitDisposable?.Dispose();
|
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 orgRotation = transform.localRotation;
|
||||||
var orgYAngle = orgRotation.eulerAngles.y;
|
var orgYAngle = orgRotation.eulerAngles.y;
|
||||||
transform.rotation = Quaternion.identity;
|
transform.rotation = Quaternion.identity;
|
||||||
|
|
@ -76,7 +86,7 @@ namespace MyGame.Scenes.MiniGame.Scripts
|
||||||
isHit.Value = false;
|
isHit.Value = false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}).AddTo(this);
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue