public void InitTank(PlayerTransFixData playerTransFixData,GameObject go) { this.m_Position = playerTransFixData.Position; this.m_Rotation = playerTransFixData.Rotation; this.m_go = go; UpdateRendering(); }
/// <summary> /// Creates a matrix for rotating points around the X-axis, from a center point. /// </summary> /// <param name="radians">The amount, in radians, by which to rotate around the X-axis.</param> /// <param name="centerPoint">The center point.</param> /// <returns>The rotation matrix.</returns> public static FixMatrix4x4 RotateX(Fix64 radians, FixVector3 centerPoint) { FixMatrix4x4 result; Fix64 c = FixMath.Cos(radians); Fix64 s = FixMath.Sin(radians); Fix64 y = centerPoint.y * (Fix64.One - c) + centerPoint.z * s; Fix64 z = centerPoint.z * (Fix64.One - c) - centerPoint.y * s; // [ 1 0 0 0 ] // [ 0 c s 0 ] // [ 0 -s c 0 ] // [ 0 y z 1 ] result.M11 = Fix64.One; result.M12 = Fix64.Zero; result.M13 = Fix64.Zero; result.M14 = Fix64.Zero; result.M21 = Fix64.Zero; result.M22 = c; result.M23 = s; result.M24 = Fix64.Zero; result.M31 = Fix64.Zero; result.M32 = -s; result.M33 = c; result.M34 = Fix64.Zero; result.M41 = Fix64.Zero; result.M42 = y; result.M43 = z; result.M44 = Fix64.One; return(result); }
public void reset(FixVector3 pos) { ignoreDirectionSlerp = true; ignorePositionSampleSlerp = true; forceCheck = true; particle.position = new BW31.SP2D.FixVector2(pos.x, pos.z); }
protected void GetPositionsFromPath(List <FixVector3> path, List <Position> posList) { if (path.Count > 0) { int j = 0; long distance = FixVector3.SqrDistance(path[j], position); if (distance <= GameConstants.EQUAL_DISTANCE) { DebugUtils.LogWarning(DebugUtils.Type.PathFinding, string.Format("movable unit {0}'s first way point is too close! distance = {1}", id, distance)); j = 1; } for ( ; j < path.Count; j++) { Position pos = new Position(); FixVector3 v = path[j]; //DebugUtils.LogWarning( DebugUtils.Type.AI_MovableUnit, string.Format( "movable unit {0}'s {1} way point is ({2}, {3}, {4})", id, j, v.x, v.y, v.z ) ); pos.x = v.vector3.x; pos.y = v.vector3.y; pos.z = v.vector3.z; posList.Add(pos); } } }
public override void updateLogic() { bool actionOver = false; m_fixMoveElpaseTime += GameData.g_fixFrameLen; Fix64 timeScale = m_fixMoveElpaseTime / m_fixMoveTime; if (timeScale >= (Fix64)1) { timeScale = (Fix64)1; actionOver = true; } FixVector3 elpaseDistance = new FixVector3(m_fixv3MoveDistance.x * timeScale, m_fixv3MoveDistance.y * timeScale, m_fixv3MoveDistance.z * timeScale); FixVector3 newPosition = new FixVector3(m_fixMoveStartPosition.x + elpaseDistance.x, m_fixMoveStartPosition.y + elpaseDistance.y, m_fixMoveStartPosition.z + elpaseDistance.z); unit.m_fixv3LogicPosition = newPosition; if (actionOver) { removeSelfFromManager(); if (null != actionCallBackFunction) { actionCallBackFunction(); } } }
void onBallLanded(FixVector2 point, bool pass, int times, FixVector3 velocity, Fix64 preHeightVelocity) { if (times == 1) { endShoot(); } }
public MonsterData(int monsterId, CampType campId, ObjectType type) { m_MonsterId = monsterId; m_CampId = campId; m_Type = type; m_SkillList = new List <SkillNode>(); m_MonsterAttrNode = FSDataNodeTable <MonsterAttrNode> .GetSingleton().FindDataByType(monsterId); Moba3v3NaviNode naviNode = FSDataNodeTable <Moba3v3NaviNode> .GetSingleton().FindDataByType((int)type - 1); m_NaviPos = campId == CampType.BLUE ? new FixVector3((Fix64)naviNode.naviPoint2.x, (Fix64)naviNode.naviPoint2.y, (Fix64)naviNode.naviPoint2.z) : new FixVector3((Fix64)naviNode.naviPoint1.x, (Fix64)naviNode.naviPoint1.y, (Fix64)naviNode.naviPoint1.z); if (m_MonsterAttrNode == null) { return; } for (int i = 0; i < m_MonsterAttrNode.skill_id.Length; i++) { SkillNode skillNode = FSDataNodeTable <MonsterSkillNode> .GetSingleton().FindDataByType(m_MonsterAttrNode.skill_id[i]); m_SkillList.Add(skillNode); } m_HP = m_MaxHP = m_MonsterAttrNode.hp; m_MonsterModelPath = m_MonsterAttrNode.modelNode.respath; m_MonsterResourceName = m_MonsterModelPath.Split('/')[3]; }
/// <summary> /// 遍历状态 /// </summary> public void UpdateLogic() { Fix64 distince = FixVector3.Distance(m_TargetObject.m_Pos, m_Pos); if (distince < m_AttackDistince) { m_TargetObject.FallDamage(50); Destroy(); } else { //普通攻击子弹自动改变朝向 FixVector3 relativePos = m_TargetObject.m_Pos - m_Pos; Quaternion rotation = Quaternion.LookRotation(relativePos.ToVector3(), Vector3.up); m_Angle = relativePos.GetNormalized(); m_Pos += m_Angle * m_AttackSpeed; #region 显示层 if (GameData.m_IsExecuteViewLogic) { if (m_Attack != null) { m_Attack.transform.rotation = rotation; m_Attack.transform.position += m_Pos.ToVector3(); } } #endregion } }
//设置缩放值 public void setScale(FixVector3 value) { m_fixv3LogicScale = value; #if _CLIENTLOGIC_ m_gameObject.transform.localScale = value.ToVector3(); #endif }
private void Moving(int deltaTime) { PathAgent agent = owner.pathAgent; agent.Move(deltaSpeed); long distance = FixVector3.SqrDistance(targetPosition, owner.position); if (distance <= FixVector3.one.magnitude) { state = State.DashEnd; waitingChangeState = false; LogicUnit target = owner.target; if (target != null && target.Alive() && target.id == owner.target.id) { AttributeEffect ae = GenerateAttributeEffect(attributeEffects[0]); ae.Attach(owner, target); } DebugUtils.Log(DebugUtils.Type.AI_Skill, string.Format("YueGuangChongCi: arrive target position, change state to {0}", state)); } else { DebugUtils.Log(DebugUtils.Type.AI_Skill, string.Format("YueGuangChongCi: distance = {0}, step = {1}", distance, stepLength)); } }
public bool TargetWithInAttackArea() { long distance = FixVector3.SqrDistance(owner.target.position, owner.position); long attackDistance = owner.GetAttackArea(); return(distance < attackDistance); }
public override void SyncMessageHandler(FixVector3 position) { targetPosition = position; DebugUtils.Log(DebugUtils.Type.AI_Skill, "YueGuangChongCi begin dash"); state = State.DashStart; }
public override void Update(int deltaTime) { base.Update(deltaTime); if (owner.target != null && owner.target.Alive()) { long distance = FixVector3.SqrDistance(owner.brithPosition, owner.position); if (distance < owner.maxChaseDistance) { owner.WaypointHandler(); owner.pathAgent.Move(owner.speed * deltaTime); // After move, Check the crystal's position is in the attack area. FixVector3 v = owner.target.position; distance = FixVector3.SqrDistance(v, owner.position); long attackDistance = owner.GetAttackAera(); if (distance < attackDistance) { owner.Attack(owner.target); } } else { owner.Walk(owner.brithPosition); } } else { owner.Walk(owner.brithPosition); } }
/// <summary> /// Transforms a vector by the given matrix. /// </summary> /// <param name="vector">The vector to transform.</param> /// <param name="matrix">The transform matrix.</param> /// <param name="result">The transformed vector.</param> public static void Transform(ref FixVector3 vector, ref FixMatrix4x4 matrix, out FixVector4 result) { result.x = vector.x * matrix.M11 + vector.y * matrix.M12 + vector.z * matrix.M13 + matrix.M14; result.y = vector.x * matrix.M21 + vector.y * matrix.M22 + vector.z * matrix.M23 + matrix.M24; result.z = vector.x * matrix.M31 + vector.y * matrix.M32 + vector.z * matrix.M33 + matrix.M34; result.w = vector.x * matrix.M41 + vector.y * matrix.M42 + vector.z * matrix.M43 + matrix.M44; }
private void FindOpponent() { LogicUnit t = FindOpponentSoldier(mark, position, realAttakDistance); if (t == null) { t = FindOpponentCrystalCar(mark, position, realAttakDistance); } if (t == null) { t = FindOpponentDemolisher(mark, position, realAttakDistance); } if (t != null) { long distance = FixVector3.SqrDistance(t.position, position); long attackDistance = realAttakDistance + t.modelRadius; DebugUtils.LogWarning(DebugUtils.Type.AI_Tower, string.Format("tower {0} finds the target {1} of type {2}, distance = {3}, attackDistance = {4}.", id, t.id, t.type, distance, attackDistance)); if (distance < attackDistance) { Attack(t); } } }
//设置旋转值 public void setRotation(FixVector3 value) { m_fixv3LogicRot = value; #if _CLIENTLOGIC_ m_gameObject.transform.localEulerAngles = value.ToVector3(); #endif }
private void UpdateMoveByDirection() { var currentY = Euler.y; for (; _targetEulerY - currentY > Fix64.I180; currentY += Fix64.I360) { ; } for (; currentY - _targetEulerY >= Fix64.I180; currentY -= Fix64.I360) { ; } var diff = _targetEulerY - currentY; if (diff != Fix64.Zero) { if (diff.RawValue > 0) { var add = Fix64.Min(diff, RotateSpeed); currentY = currentY + add; } else { diff = -diff; var minus = Fix64.Min(diff, RotateSpeed); currentY = currentY - minus; } Euler.y = currentY.ClampAngle(); } Position += new FixVector3(MoveSpeed * _targetSin, Fix64.Zero, MoveSpeed * _targetCos); }
/// <summary> /// 进入AI /// </summary> public void OnEnter() { if (m_Monster == null || m_Monster.m_MonsterData == null || m_Monster.m_MonsterData.m_NaviPos == null) { return; } FixVector3 relativePos = m_Monster.m_MonsterData.m_CampId == CampType.BLUE ? (m_Monster.m_MonsterData.m_NaviPos - m_Monster.m_Pos) : (m_Monster.m_Pos - m_Monster.m_MonsterData.m_NaviPos); Quaternion rotation = Quaternion.LookRotation(relativePos.ToVector3(), Vector3.up); m_Monster.m_Angles = relativePos.GetNormalized(); m_Monster.m_Rotation = (FixVector3)(rotation.eulerAngles); #region 显示层 if (GameData.m_IsExecuteViewLogic) { m_Monster.m_VGo.transform.rotation = rotation; } #endregion if (m_Monster.m_MonsterData.m_CampId == CampType.BLUE) { m_Parameter = string.Format("{0}#{1}#{2}", m_Monster.m_Angles.x, m_Monster.m_Angles.y, m_Monster.m_Angles.z); } if (m_Monster.m_MonsterData.m_CampId == CampType.RED) { m_Parameter = string.Format("{0}#{1}#{2}", -m_Monster.m_Angles.x, -m_Monster.m_Angles.y, -m_Monster.m_Angles.z); } }
public void Initialize(LogicUnit owner, ProjectileProto proto, long id, FixVector3 position, LogicUnit target) { this.id = id; this.type = LogicUnitType.Projectile; this.owner = owner; this.mark = owner.mark; this.position = position; this.target = target; targetId = target.id; metaId = proto.ID; modelId = proto.Projectile_ResouceId; hitEffectId = proto.HitEffect_ResourceId; speedFactor = ConvertUtils.ToLogicInt(proto.SpeedFactor); damage = owner.damage; projectileType = (ProjectileType)proto.ProjectileType; startPosition = position; targetPosition = target.position; speed = (targetPosition - position).normalized * speedFactor; transform.position = position.vector3; state = ProjectileState.Flying; targetDistance = 0; destination = target.position; // Temp data hurtType = AttackPropertyType.PhysicalAttack; DebugUtils.Log(DebugUtils.Type.AI_Projectile, "the projectile " + id + "'s target is " + target.id + ", speed = " + position); }
public override void updateLogic() { bool actionOver = false; m_fixMoveElapseTime += GameData.g_fixFrameLen; Fix64 timeScale = m_fixMoveElapseTime / m_fixMoveTime; if (timeScale >= (Fix64)1) { timeScale = (Fix64)1; actionOver = true; } FixVector3 elapseDistance = m_fixv3MoveDistance * timeScale; FixVector3 newPosition = m_fixMoveStartPosition + elapseDistance; unit.m_fixv3LogicPos = newPosition; if (actionOver) { removeSelfFromManager(); if (actionCallbackFunc != null) { actionCallbackFunc(); } } }
public void onShootBallOut(FBActor actor, FixVector3 velocity, Fix64 angle, FixVector3 target) { //jlx2017.05.26-log:因为行为树也要使用这个消息,所以使用fire,而不使用fire2Rendering LogicEvent.fire("onShootBallOut", actor.id); fbGame.generateRenderAction <RAL.BallShootAction>(actor.id, actor.shootingType, velocity.toVector3(), (float)angle, target.toVector3()); }
public override void Update(int deltaTime) { if (owner.target != null && owner.target.Alive() && owner.target.id == owner.targetId) { if (owner.fightTimer >= owner.fightInterval) { owner.fightTimer = 0; owner.Fight(); } else { owner.fightTimer += deltaTime; } long distance = FixVector3.SqrDistance(owner.target.position, owner.position); if (distance > owner.attackRange) { owner.target = null; owner.targetId = 0; owner.ChangeState(IdolGuardState.IDLE, owner.fsmIdle); } } else { owner.target = null; owner.targetId = 0; owner.ChangeState(IdolGuardState.IDLE, owner.fsmIdle); } }
public virtual void Walk(FixVector3 d) { DebugUtils.Log(DebugUtils.Type.AI_Npc, string.Format(" {0} {1} now change to destination {2} ", npcType, id, d)); destination = d; pathAgent.FindPath(position, destination, NavMeshAreaType.WALKABLE, OnFoundLocalWalkPath); }
void Fix64Test() { //Debug.LogError(fix1.ToString()); FixVector3 FA = new FixVector3(0f, 0f, 1f); FixVector3 FB = new FixVector3(1f, 0f, 0f); Fix64 Fangle = FixVector3.Angle(FA, FB); Debug.LogError(Fangle); Debug.LogError(FixVector3.Cross(FA, FB)); Debug.LogError(FixVector3.Rotate(FA, (Fix64)90)); Fix64 angleToH = (Fix64)2 * (Fix64)3.1415927 / (Fix64)360; Fix64 FangleSin = (Fix64)30 * angleToH; Debug.LogError("Fix64 sin = " + Fix64.Sin(FangleSin)); Debug.LogError("float sin = " + Mathf.Sin(30 * Mathf.Deg2Rad)); Vector3 A = new Vector3(0f, 0f, 1f); Vector3 B = new Vector3(1f, 0f, 0f); float angle = Vector3.Angle(A, B); Debug.LogError(angle); Debug.LogError(Vector3.Cross(A, B)); float dot = Vector3.Dot(A, B); Debug.LogError(Mathf.Acos(dot) + " " + Mathf.Acos(dot) * Mathf.Rad2Deg); Debug.LogError(Quaternion.AngleAxis(90, Vector3.up) * A); }
/// <summary> /// Creates a matrix for rotating points around the Z-axis, from a center point. /// </summary> /// <param name="radians">The amount, in radians, by which to rotate around the Z-axis.</param> /// <param name="centerPoint">The center point.</param> /// <returns>The rotation matrix.</returns> public static FixMatrix4x4 RotateZ(Fix64 radians, FixVector3 centerPoint) { FixMatrix4x4 result; Fix64 c = FixMath.Cos(radians); Fix64 s = FixMath.Sin(radians); Fix64 x = centerPoint.x * (1 - c) + centerPoint.y * s; Fix64 y = centerPoint.y * (1 - c) - centerPoint.x * s; // [ c s 0 0 ] // [ -s c 0 0 ] // [ 0 0 1 0 ] // [ x y 0 1 ] result.M11 = c; result.M12 = s; result.M13 = Fix64.Zero; result.M14 = Fix64.Zero; result.M21 = -s; result.M22 = c; result.M23 = Fix64.Zero; result.M24 = Fix64.Zero; result.M31 = Fix64.Zero; result.M32 = Fix64.Zero; result.M33 = Fix64.One; result.M34 = Fix64.Zero; result.M41 = Fix64.Zero; result.M42 = Fix64.Zero; result.M43 = Fix64.Zero; result.M44 = Fix64.One; return(result); }
public static Fix64 AngleTwo(FixVector3 a, FixVector3 b) { Fix64 cos = Dot(a, b) / (a.Magnitude * b.Magnitude); cos = cos < -Fix64.One ? -Fix64.One : (cos > Fix64.One ? Fix64.One : cos); return((Fix64)Math.Round(Math.Acos((float)cos), 3)); }
/// <summary> /// Creates a matrix for rotating points around the Y-axis, from a center point. /// </summary> /// <param name="radians">The amount, in radians, by which to rotate around the Y-axis.</param> /// <param name="centerPoint">The center point.</param> /// <returns>The rotation matrix.</returns> public static FixMatrix4x4 RotateY(Fix64 radians, FixVector3 centerPoint) { FixMatrix4x4 result; Fix64 c = FixMath.Cos(radians); Fix64 s = FixMath.Sin(radians); Fix64 x = centerPoint.x * (Fix64.One - c) - centerPoint.z * s; Fix64 z = centerPoint.x * (Fix64.One - c) + centerPoint.x * s; // [ c 0 -s 0 ] // [ 0 1 0 0 ] // [ s 0 c 0 ] // [ x 0 z 1 ] result.M11 = c; result.M12 = Fix64.Zero; result.M13 = -s; result.M14 = Fix64.Zero; result.M21 = Fix64.Zero; result.M22 = Fix64.One; result.M23 = Fix64.Zero; result.M24 = Fix64.Zero; result.M31 = s; result.M32 = Fix64.Zero; result.M33 = c; result.M34 = Fix64.Zero; result.M41 = x; result.M42 = Fix64.Zero; result.M43 = z; result.M44 = Fix64.One; return(result); }
//- 创建子弹 // // @param id 子弹id // @param dest 由谁发出来的子弹 // @param src 由谁发出来的子弹 // @param poShootStartPosition 子弹生成的位置 // @param poShootEndPosition 子弹要到达的位置 // @return none public void createBullet(LiveObject src, LiveObject dest, FixVector3 poShootStartPosition, FixVector3 poShootEndPosition) { BaseBullet bullet = null; //直射子弹 bullet = new DirectionShootBullet(); //根据名字加载资源 bullet.createBody(m_scBulletName); bullet.initData(src, dest, poShootStartPosition, poShootEndPosition); bullet.shoot(); if (null != bullet) { //刷新显示位置 bullet.updateRenderPosition(0); //立即记录最后的位置,否则通过vector3.lerp来进行移动动画时会出现画面抖动的bug bullet.recordLastPos(); //加入子弹列表 GameData.g_listBullet.Add(bullet); } }
public FixVector3 GetNormalized() { FixVector3 v = new FixVector3(this); v.Normalize(); return(v); }
public void Walk(FixVector3 d) { // ignore walk when car near by the born point if ((d - position).sqrMagnitude <= 0.5) { return; } if (state == CrystalCarState.IDLE) { DebugUtils.Log(DebugUtils.Type.AI_CrystalCar, "crystal car " + id + " enters IDLE2WALK state, target position = " + d); ChangeState(CrystalCarState.IDLE2WALK, fsmPlaceHolder); } else { return; } DebugUtils.Log(DebugUtils.Type.AI_CrystalCar, string.Format(" {0}'s crystal car {1} begin to go {2} ", mark, id, d)); if (owner) { pathAgent.FindPath(position, d, NavMeshAreaType.WALKABLE, OnWalkPathComplete); } }