public void OnMoveTo(Vector2 from, Vector2 to) { ServerMoveData data = new ServerMoveData(); data.StartPosition = from; data.Destination = to; OnSynchronize(data); }
public void OnMoveStop(Vector2 stopPos, float stopDir) { ServerMoveData data = new ServerMoveData(); data.StartPosition = new Vector2(transform.position.x, transform.position.z); data.Destination = stopPos; data.yaw = stopDir; OnSynchronize(data, MoveStatus.PrepareStop); }
public void OnMonsterMoveTo(Vector2 to) { if (actorObj.IsDeath()) { return; } ServerMoveData data = new ServerMoveData(); data.StartPosition = new Vector2(transform.position.x, transform.position.z); data.Destination = to; OnSynchronize(data); }
public void OnSynchronize(ServerMoveData packet, MoveStatus state = MoveStatus.Running) { /* * //强制设置位置 * transform.position = new Vector3(packet.Destination.x, 0, packet.Destination.y); * float height = pathFinder.GetTerrainHeight(transform.position.x, transform.position.z); * transform.position = new Vector3(transform.position.x, height, transform.position.z); * return; */ Status = state; destination = new Vector3(packet.Destination.x, 0, packet.Destination.y); moveDirection = (packet.Destination - new Vector2(transform.position.x, transform.position.z)).normalized; moveSpeed = moveDirection * GetSpeed() * 1.1f; //临时加速其它玩家和怪物,使其被到达目标位置的可能性增加 moveSpeed = new Vector3(moveSpeed.x, 0, moveSpeed.y); lastPosition = transform.position; yaw = packet.yaw; if (Status == MoveStatus.Running) { FaceTo(destination); } /* * startLogicTime = packet.StartTime; * * //计算到目标位置的距离和方向,用于判定是否需要加速 * Vector2 xzPosition = transform.position; * Vector2 dir = packet.Destination - xzPosition; * float length = dir.magnitude; * dir.Normalize(); * * //计算可用于移动到目标位置的可用时间片 * //todo ,get timeService from logic module * LatencyEstimate timeService = new LatencyEstimate(); * float serverMoveTime = (packet.Destination - packet.StartPosition).magnitude / packet.Speed; * * float diffTime = packet.StartTime - timeService.ServerTime; * float expectMoveTime = diffTime > 0 ? serverMoveTime + diffTime : serverMoveTime - diffTime; * * Vector3 speed2D; * //计算需要的移动速度 * float expectSpeed = length / expectMoveTime; * //计算速度和做位置校正 * //误差太大,则强制把目标位置设置到服务器指定位置(强制拉人) * if (expectSpeed > packet.Speed * MaxSmoothSpeedTimes) * { * SetServerPosition(packet.StartPosition); * speed2D = dir * packet.Speed ; * } * else * { * //平滑加/减速追赶服务器目标位置 * speed2D = dir * expectSpeed ; * } * moveSpeed = new Vector3(speed2D.x ,0 ,speed2D.y); * * //设置目标位置,朝向目标 * destination = new Vector3(packet.Destination.x ,0 , packet.Destination.y); * FaceTo(destination); * Status = MoveStatus.Running; */ //StateParameter parameter = new StateParameter(); //parameter.state = ACTOR_STATE.AS_RUN; //actorObj.RequestChangeState(parameter); }