public void Syncm_transform() { if (ShouldUpdatePositionToCastObj && m_actor != null) { BaseTool.SetPosition(transform, m_actor.transform.position); m_transform.rotation = m_actor.transform.rotation; } }
protected override void UpdateImpl(float deltaTime) { if (actorObj.IsDeath()) { return; } if (actorObj.GetCurState() != ACTOR_STATE.AS_RUN) { actorObj.RequestChangeState(ACTOR_STATE.AS_RUN); } if ((transform.position - lastPosition).sqrMagnitude > 1e-3f) { lastPosition = transform.position; moveDirection = destination - lastPosition; //moveDirection = destination - transform.position; moveDirection.y = 0; moveDirection.Normalize(); moveSpeed = moveDirection * GetSpeed() * 1.1f; } Vector3 movePath = deltaTime * moveSpeed; float sqrDist = XZDistanceSqr(transform.position, destination); float moveSqrDist = movePath.sqrMagnitude; if (moveSqrDist >= sqrDist) { //transform.position = destination; BaseTool.SetPosition(transform, destination); if (Status == MoveStatus.PrepareStop) { OnChangeDir(yaw); } Stop(); } else { //transform.position = transform.position + movePath; BaseTool.SetPosition(transform, transform.position + movePath); } float height = pathFinder.GetTerrainHeight(transform.position.x, transform.position.z); // transform.position = new Vector3(transform.position.x, height, transform.position.z); BaseTool.SetPosition(transform, new Vector3(transform.position.x, height, transform.position.z)); lastPosition = transform.position; }
public virtual void SetServerPosition(Vector2 position) { Vector3 clientPosition = ServerPositionConverter.ConvertToClientPosition(position); clientPosition.y = pathFinder.GetTerrainHeight(clientPosition.x, clientPosition.z); // transform.position = clientPosition; BaseTool.SetPosition(transform, clientPosition); status = MoveStatus.Stopped; //Debug.LogWarning(string.Format("name : {0} ,pos({1} ,{2})", gameObject.name, clientPosition.x, clientPosition.z)); }
void ApplyForce(ActorObj actor) { Vector3 diff = (transform.position - actor.transform.position); if (actor.CheckIfNotBossOrInQijue()) { if (diff.sqrMagnitude <= radiusSQ) { Vector3 distance = diff.normalized * speed * Time.deltaTime; distance.y = 0; Vector3 dest = actor.transform.position + distance; if (BaseTool.instance.CanMoveToPos(actor.transform.position, dest, actor.GetColliderRadius())) { BaseTool.SetPosition(actor.transform, actor.transform.position + distance); } } } }
public override void Init(ISkillCellData cellData, SkillBase skillBase) { m_skillBase = skillBase; cellDesc = (PositionCellDesc)cellData; skillBase.ShouldUpdatePositionToCastObj = false; orgPos = m_skillBase.m_actor.transform.position; orgFront = m_skillBase.m_actor.transform.forward; orgRight = m_skillBase.m_actor.transform.right; targetTransform = null; if (cellDesc != null) { //有对应的行为技能ID if (cellDesc.BehaviorSkillId > 0) { behaviorSkillDesc = skillBase.m_actor.GetCurSkillDesc(cellDesc.BehaviorSkillId); if (behaviorSkillDesc != null) { ActorObj targetActorBase = skillBase.m_actor.GetTargetFromSelector(behaviorSkillDesc, null); if (targetActorBase != null) { targetTransform = targetActorBase.transform; } } } else { //默认技能行为 if (skillBase.m_hitActor != null) { targetTransform = skillBase.m_hitActor.transform; } } //是否attach到actor上 if (cellDesc.AttachToActor) { if (cellDesc.SyncRotation) { skillBase.transform.parent = targetTransform; BaseTool.ResetTransform(skillBase.transform); skillBase.transform.localPosition += cellDesc.AttachOffset; } else { SyncPosition(); BaseTool.SetLocalPosition(m_skillBase.transform, curMovingPos); } } else { //走相应的轨迹 if (cellDesc.PointList.Count > 0) { BaseTool.SetPosition(skillBase.transform, GetPos(0)); skillBase.transform.forward = skillBase.transform.forward; currentIndex = 0; } } //同步施法者位置 if (cellDesc.SyncOwnerPosition) { BaseTool.SetPosition(m_skillBase.m_actor.transform, skillBase.transform.position); } Reset(); if (cellDesc.DelayMovingTime >= 0) { //吟唱后,发射子弹 float curTime = m_skillBase.GetCurActionTime(); if (cellDesc.DelayMovingTime <= curTime) { StartToMove(); } else { Invoke("StartToMove", cellDesc.DelayMovingTime - curTime); } } } }
void LateUpdate() { if (isStartMoving) { if (cellDesc.AttachToActor == false && cellDesc.Speed > 0 && cellDesc.PointList.Count > 1) { int nextIndex = currentIndex + 1; if ((cellDesc.PointList.Count > nextIndex)) { Vector3 start = GetPos(currentIndex); if (cellDesc.PointList[nextIndex].SkipWhenTouch) { start = curMovingPos; } Vector3 end = GetPos(nextIndex); //如果回到actor重新获取信息 bool backToActor = (cellDesc.PointList[nextIndex].BackToActor && targetTransform != null); if (backToActor) { start = curMovingPos; end = GetTargetPos(); } Vector3 dir = end - start; float disSQ = dir.sqrMagnitude; dir.Normalize(); m_skillBase.transform.LookAt(end); Vector3 dest = curMovingPos + dir * Time.deltaTime; bool reachedEnd = false; //到当前点的条件 if (backToActor) { reachedEnd = (disSQ <= 1); } else { reachedEnd = ((dest - start).sqrMagnitude >= disSQ); } //是否到了当前点 if (reachedEnd) { //是否在该点结束技能 if (cellDesc.PointList[nextIndex].EndSkill) { m_skillBase.SkillEnd(); } //继续找下一个移动节点 curMovingPos = end; m_skillBase.transform.forward = dir; currentIndex++; } else { curMovingPos += dir * cellDesc.Speed * Time.deltaTime; } BaseTool.SetPosition(m_skillBase.transform, curMovingPos); } } else if (cellDesc.AttachToActor == true && cellDesc.SyncRotation == false) { //只同步位移,不同步旋转的情况 SyncPosition(); } if (ProcessRotation(curMovingPos) == false) { //不旋转直接设置位置 BaseTool.SetLocalPosition(m_skillBase.transform, curMovingPos); } } }
void TakeAwayTargets(Vector3 translation) { Vector3 aimPos, wallPos, pos0, dir; List <int> NoUseList = null; if (m_TakeAwayGameObjectMap.Count > 0) { NoUseList = new List <int>(); } if (m_param.bCanNotMoveWhenTakenAway) { bool canMoveTarget = false; Vector3 tmpPos = this.transform.position; if (m_TakeAwayGameObjectMap.Count > 0) { //只有在地面上的位置,才是移动目标的有效位置 if (m_baseTool.IsAboveTheGround(tmpPos)) { canMoveTarget = true; } } if (canMoveTarget) { foreach (int i in m_TakeAwayGameObjectMap.Keys) { ActorObj actorBase = m_TakeAwayGameObjectMap[i].GetComponent <ActorObj>(); if (actorBase != null) { float radius = actorBase.GetColliderRadius(); if (BaseTool.instance.CanMoveToPos(actorBase.transform.position, tmpPos, radius)) { //m_TakeAwayGameObjectMap[i].transform.position = new Vector3(tmpPos.x, m_TakeAwayGameObjectMap[i].transform.position.y, tmpPos.z); BaseTool.SetPosition(m_TakeAwayGameObjectMap[i].transform, tmpPos); } } } } } else { foreach (int i in m_TakeAwayGameObjectMap.Keys) { if (m_TakeAwayGameObjectMap[i] != null) { aimPos = m_TakeAwayGameObjectMap[i].transform.position + translation; wallPos = m_baseTool.GetWallHitPoint(m_TakeAwayGameObjectMap[i].transform.position, aimPos); if (!wallPos.Equals(aimPos)) { // Debug.DrawLine(wallPos, aimPos,Color.cyan); dir = translation; dir.Normalize(); //存在空气墙 //unity的raycast是向下忽略的,所以不能再下边界做判断,给定的时候,往回取一点值 Vector3 wallGroundPos = m_baseTool.GetGroundPoint(wallPos - dir * 0.1f); float distance = Vector3.Distance(m_TakeAwayGameObjectMap[i].transform.position, wallGroundPos); distance -= 0.4f; pos0 = m_TakeAwayGameObjectMap[i].transform.position + translation.normalized * distance; aimPos = m_baseTool.GetGroundPoint(pos0); m_TakeAwayGameObjectMap[i].transform.Translate(aimPos - m_TakeAwayGameObjectMap[i].transform.position, Space.World); NoUseList.Add(i); } else { m_TakeAwayGameObjectMap[i].transform.Translate(translation, Space.World); } } } } if (NoUseList != null) { for (int i = 0; i < NoUseList.Count; ++i) { //清除物件前,恢复动作 ActorObj actorBase = m_TakeAwayGameObjectMap[NoUseList[i]].GetComponent <ActorObj>(); if (actorBase != null) { actorBase.CanCurveMove(); } m_TakeAwayGameObjectMap.Remove(NoUseList[i]); } } }
public void UpdateFrame() { if (!m_needMove) { return; } float fDistance = Vector3.Distance(m_MoveDestPos, m_LastPos); if (fDistance < 0.01f) { SetMoveState(false); return; } //if (!m_actor.IsPlayingAction(m_curPlayAction)) //{ // //m_needMove = false; // SetMoveState(false); // return; //} //插值开始 float diffTime = Time.time - m_beginTime; if (m_LastPos != Vector3.zero) { m_DeltaPos += m_transform.position - m_LastPos; } //计算当前帧的位置 Vector3 curPos = m_transform.position; Vector3 nextPos = GetPos(diffTime) + m_DeltaPos; Vector3 moveDir = nextPos - curPos; moveDir.Normalize(); //目标移动位置 Vector3 moveDstPos = nextPos; Vector3 groundPos = BaseTool.instance.GetGroundPoint(moveDstPos); if (groundPos == Vector3.zero) { if (m_actor.mActorType == ActorType.AT_MONSTER || m_actor.mActorType == ActorType.AT_BOSS || m_actor.mActorType == ActorType.AT_MECHANICS) { BaseTool.SetPosition(m_transform, CoreEntry.gActorMgr.MainPlayer.transform.position); } else { BaseTool.SetPosition(m_transform, m_LastPos); } return; } else { BaseTool.SetPosition(m_transform, groundPos); } m_LastPos = m_transform.position; }
public void SetPosition(Vector3 position) { // transform.position = position; BaseTool.SetPosition(transform, position); }
protected override void UpdateImpl(float deltaTime) { if (XZDistanceSqr(currentDestination, transform.position) < 1e-3f) { if (pointList.Count < 1) { Stop(); return; } currentDestination = pointList.Dequeue(); FaceTo(currentDestination); SendMoveTo(transform.position, currentDestination); } //todo ,get move speed from actor float speed = GetSpeed(); //float speed = 6.0f; if (isSlide) { speed *= 0.2f; } float dist; float moveDist = deltaTime * speed; float remainDist = moveDist; Vector3 prevPositioin = transform.position; while (true) { dist = XZDistance(currentDestination, prevPositioin); if (remainDist <= dist) { break; } if (pointList.Count < 1) { currentDestination.y = pathFinder.GetTerrainHeight(currentDestination.x, currentDestination.z); BaseTool.SetPosition(transform, currentDestination); Stop(); return; } remainDist -= dist; prevPositioin = currentDestination; currentDestination = pointList.Dequeue(); FaceTo(currentDestination); SendMoveTo(transform.position, currentDestination); } Vector3 pos = prevPositioin + (currentDestination - prevPositioin).normalized * remainDist; float height = pathFinder.GetTerrainHeight(pos.x, pos.z); if (0 != height) { pos.y = height; } //SendMoveTo(transform.position, currentDestination); //transform.position = pos; BaseTool.SetPosition(transform, pos); }
//浮空受击 public void DoBehit() { //浮空状态不能释放技能 m_BehitState.isNonControl = true; //离地面高度 float height = GetHeightToGround(); if (height <= 0.1f) { return; } if (nCount > 2) { m_actor.StopAll(); string clipName = "hit006"; m_actor.PlayAction(clipName); m_actor.SetActionSpeed(clipName, 2f); m_actor.UseCurveData1(clipName, 2.5f); m_isUseGravity = false; // ExitBehitState(); if (!m_actor.IsHadAction(clipName)) { Vector3 vCurPos = m_actor.transform.position; RaycastHit curHit; //强拉到地面 if (Physics.Raycast(vCurPos, -Vector3.up, out curHit, 10, m_groundLayerMask)) { vCurPos.y = curHit.point.y; } BaseTool.SetPosition(m_transform, vCurPos); } float actionLen = m_actor.GetActionLength(clipName); Invoke("ExitBehitState", actionLen); nCount = 0; return; } nCount++; m_behitParame = m_actor.damageBebitParam; int skillID = m_behitParame.damgageInfo.skillID; //ActorObj m_hitActorBase = m_behitParame.damgageInfo.attackActor; //只处理带位移的普通技能 //LuaTable skillDesc = m_hitActorBase.GetCurSkillDesc(skillID); char bodyType = (char)m_actor.BodyType; int weight = 1; //技能力度纠正 if (m_behitParame.damgageInfo.weight > 0) { weight = m_behitParame.damgageInfo.weight; LogMgr.UnityLog("Gravity dobehit skillid=" + skillID + ", reset weight=" + weight); } //获取技能受击反馈 SkillBehitDisplayDesc behitDisplay = m_gameDataBase.GetSkillBehitDisplayDesc(weight, bodyType); if (behitDisplay == null) { return; } //没有硬直,定格,没有位移 if (!behitDisplay.isNonControl) { return; } //带位移 float moveDistance = 0; //动作 if (behitDisplay.behitType == BehitType.BT_NORMAL) { //普通受击 // moveDistance = skillDesc.hitMoveDistance; moveDistance = 0.2f; } else if (behitDisplay.behitType == BehitType.BT_HITBACK) { //美术位移 if (!m_behitParame.damgageInfo.isNotUseCurveMove) { string clipName = behitDisplay.actionList[0]; moveDistance = m_actor.GetAnimationCurveLength(clipName); //LogMgr.UnityLog("moveDistance=" + moveDistance + ", clipName=" + clipName); } } else if (behitDisplay.behitType == BehitType.BT_HITDOWN) { m_actor.StopAll(); string clipName = behitDisplay.actionList[0]; m_actor.PlayAction(clipName); m_actor.UseCurveData1(clipName, 2.5f); m_isUseGravity = false; // ExitBehitState(); if (!m_actor.IsHadAction(clipName)) { Vector3 vCurPos = m_actor.transform.position; RaycastHit curHit; //强拉到地面 if (Physics.Raycast(vCurPos, -Vector3.up, out curHit, 10, m_groundLayerMask)) { vCurPos.y = curHit.point.y; } BaseTool.SetPosition(m_transform, vCurPos); } float actionLen = m_actor.GetActionLength(clipName); Invoke("ExitBehitState", actionLen); return; } else if (behitDisplay.behitType == BehitType.BT_HITSKY) { //浮空追击 CancelInvoke("MoveDistanceEnd"); CancelInvoke("AutoCancelStatic"); F_ACCE = 0; // SetOriginV(skillDesc.hitSkyOriginV, skillDesc.hitSkyAngle); m_actor.StopAll(); m_actor.PlayAction("hit013", false); return; } //LogMgr.UnityLog("moveDistance=" + moveDistance); if (height < 0.5f) { return; } //没有位移 if (moveDistance <= 0.001) { //F_ACCE = G_ACCE; SetOriginV(1, 90); m_actor.StopAll(); m_actor.PlayAction("hit013", false); } else { //当前的高度 SetOriginV(3, 75); m_actor.StopAll(); m_actor.PlayAction("hit013", false); } }
// Update is called once per frame void Update() { if (m_actor == null) { return; } if (m_actor.IsDeath()) { m_isUseGravity = false; return; } if (m_actor.IgnoredGravityMotion) { m_isUseGravity = false; return; } if (!m_isUseGravity) { nCount = 0; return; } float diffTime = Time.time - m_startMotionTime; //Y轴当前速度 float vY = m_originVelocity.vSubY - (G_ACCE - F_ACCE) * diffTime; //Y轴位移 float dY = (m_originVelocity.vSubY - 0.5f * (G_ACCE - F_ACCE) * diffTime) * diffTime;; if (m_gravityMotionType == GravityMotionType.GMT_DOWN) { dY = dY * 0.8f; } //Z轴位移 float dZ = m_originVelocity.vSubZ * diffTime; Vector3 movePos = m_attackObjForward.normalized * dZ; //LogMgr.UnityLog("movePos="+movePos.ToString("f4")+", dir="+m_attackObjForward.normalized.ToString("f4")); Vector3 curPos = m_transform.position; Vector3 aimPos = m_startPos + new Vector3(movePos.x, dY, movePos.z); //m_transform.position = m_startPos + new Vector3(movePos.x, dY, movePos.z); bool isOverHeight = false; //float heigth = m_transform.position.y - m_startToSkyPos.y; float heigth = aimPos.y - m_startToSkyPos.y; if (heigth > 5) { //m_transform.position -= new Vector3(0, heigth-5, 0); aimPos -= new Vector3(0, heigth - 2, 0); isOverHeight = true; } //是否碰到墙壁 bool isToWall = false; if (!(Mathf.Abs(m_originVelocity.vSubZ) <= 0.0001)) { Vector3 dir = m_attackObjForward; RaycastHit beHit; if (!BaseTool.instance.CanMoveToPos(curPos, aimPos, m_curRadius) || Physics.Raycast(m_transform.position, dir, out beHit, m_curRadius + 0.5f, m_groundLayerMask)) { //碰到阻挡墙,直接下落 aimPos = curPos; isToWall = true; } } //Vector3 groundPos = BaseTool.instance.GetGroundPoint(m_transform.position); //if (aimPos.y < groundPos.y) //{ // aimPos.y = groundPos.y + 0.01f; //} BaseTool.SetPosition(m_transform, aimPos); //到达最高点, 碰到墙壁 if (isOverHeight || isToWall || (m_gravityMotionType == GravityMotionType.GMT_UP && vY <= 0.0001)) { F_ACCE = 0; if (isOverHeight || isToWall) { SetOriginV(1, 270); } else { //有水平速度,保持不变 if (!(Mathf.Abs(m_originVelocity.vSubZ) <= 0.0001)) { m_gravityMotionType = GravityMotionType.GMT_DOWN; return; } m_actor.StopAll(); SetOriginV(0, 270); m_actor.PlayAction("hit011", false); } } }