public void SetData(Vector3 dest, float height, float duration, float upward_ratio, LuaFunction cbref) { if (duration <= 0 || upward_ratio <= 0 || upward_ratio >= 1) { return; } _HoriVelocity = (dest - _Owner.position) / duration; _HoriVelocity.y = 0; _OrigHeight = _Owner.position.y; _DestHeight = dest.y; _PeakHeight = _OrigHeight + height; float upward_time = duration * upward_ratio; _UpwardAcc = 2 * height / (upward_time * upward_time); _OrigVertVelocity = 2 * height / upward_time; float downward_time = duration * (1 - upward_ratio); _DownwardAcc = 2 * height / (downward_time * downward_time); OnFinishCallbackRef = cbref; _CurPhase = JUMP_PHASE.JP_UPWARDS; _ElapseTime = 0; }
public void SetData(Vector3 dest, float height, float last_time, float up_ratio, OnBehaviorFinsh on_finish) { if(last_time <= 0 || up_ratio <= 0 || up_ratio >= 1) return; dest.y += 50.0f; _Destination = dest; _Destination.y = ECUtility.GetSupportPlaneHeight(dest); _StartHeight = m_ECObj.transform.position.y; _StopHeight = _Destination.y; _MaxHeight = height + _StartHeight; //Debug.LogWarning("_StartHeight = " + _StartHeight + " _StopHeight = " + _StopHeight + " _MaxHeight = " + _MaxHeight + " height = " + height); float upward_time = last_time*up_ratio; _UpAcceleration = 2 * height / (upward_time * upward_time); _StartYVelocity = 2 * height / upward_time; float downward_time = last_time*(1-up_ratio); _DownAcceleration = 2 * (_MaxHeight - _StopHeight) / (downward_time * downward_time); _HoriVelocity = (_Destination - m_ECObj.transform.position) / last_time; m_onFinish = on_finish; _CurPhase = JUMP_PHASE.JP_UPWARD; _LastScecond = 0; }
public override bool Tick(float dt) { Vector3 delta = _HoriVelocity*dt; Vector3 cur_pos = m_ECObj.transform.position + delta; _LastScecond += dt; if(_CurPhase == JUMP_PHASE.JP_UPWARD) { float h = _StartYVelocity*_LastScecond - 0.5f*_UpAcceleration*_LastScecond*_LastScecond + _StartHeight; if (_StartYVelocity - _UpAcceleration * _LastScecond > 0) cur_pos.y = h; else { cur_pos.y = _MaxHeight; _CurPhase = JUMP_PHASE.JP_DOWNWARD; _LastScecond = 0; } m_ECObj.transform.position = cur_pos; } else if(_CurPhase == JUMP_PHASE.JP_DOWNWARD) { float h = _MaxHeight - 0.5f*_DownAcceleration*_LastScecond*_LastScecond; if (h > _StopHeight) { cur_pos.y = h; m_ECObj.transform.position = cur_pos; } else { m_ECObj.transform.position = _Destination; _CurPhase = JUMP_PHASE.JP_END; } } return _CurPhase == JUMP_PHASE.JP_END; }
public override bool Tick(float dt) { Vector3 delta = _HoriVelocity * dt; Vector3 cur_pos = _Owner.position + delta; _ElapseTime += dt; if (_CurPhase == JUMP_PHASE.JP_UPWARDS) { float h = _OrigVertVelocity * _ElapseTime - 0.5f * _UpwardAcc * _ElapseTime * _ElapseTime; if (_OrigVertVelocity - _UpwardAcc * _ElapseTime > 0) { cur_pos.y = h; } else { cur_pos.y = _PeakHeight; _CurPhase = JUMP_PHASE.JP_DOWNWARDS; _ElapseTime = 0; } } else if (_CurPhase == JUMP_PHASE.JP_DOWNWARDS) { float h = _PeakHeight - 0.5f * _DownwardAcc * _ElapseTime * _ElapseTime; if (h > _DestHeight) { cur_pos.y = h; } else { cur_pos.y = _DestHeight; _CurPhase = JUMP_PHASE.JP_END; } } return(_CurPhase == JUMP_PHASE.JP_END); }