public static IM.Vector3 RotateTowards(IM.Vector3 from, IM.Vector3 to, IM.Number step, bool bClockWise, IM.Vector3 StartPos) { IM.Vector3 vRotAxis = IM.Vector3.up; vRotAxis *= bClockWise ? IM.Number.one : -IM.Number.one; IM.Quaternion rot = IM.Quaternion.AngleAxis(IM.Math.Rad2Deg(step), vRotAxis.normalized); IM.Vector3 destTo = rot * from; { //StartPos.y = 1.0f; //Debug.DrawLine(StartPos, StartPos + destTo * 3.0f, Color.red); //Debug.Log("vRotAxis: " + vRotAxis ); } return(destTo); }
private static void ParseTransformToXML(Transform trans, XmlDocument doc, XmlNode parent) { XmlElement item = doc.CreateElement(trans.name); XmlElement pointNode = doc.CreateElement("Point"); XmlElement rotationNode = doc.CreateElement("Rotation"); IM.Vector3 point = IM.Editor.Tools.Convert(trans.localPosition); pointNode.InnerText = point.ToString(); IM.Quaternion rotation = IM.Editor.Tools.Convert(trans.localRotation); rotationNode.InnerText = rotation.ToString(); item.AppendChild(pointNode); item.AppendChild(rotationNode); parent.AppendChild(item); }
void UpdatePlayer() { //Root bool calcRootMotion = false; foreach (PlayInfo prev in _prevInfos) { if (prev.enableRootMotion) { calcRootMotion = true; } } if (_curInfo.enableRootMotion) { calcRootMotion = true; } if (calcRootMotion) { IM.Vector3 deltaMove; IM.Number deltaAngle; GetRootPosAndRot(out deltaMove, out deltaAngle, true); } IM.Vector3 playerPos = _player.position; IM.Quaternion playerRotation = _player.rotation; IM.Vector3 playerScale = _player.scale; _player.rootPos = playerPos + playerRotation * _player.rootLocalPos * playerScale; //Ball _player.ballSocketLocalPos = GetNodePosition(SampleNode.Ball); _player.ballSocketPos = _player.TransformNodePosition(SampleNode.Ball, _player.ballSocketLocalPos); if (_player.m_bWithBall) { _player.m_ball._position = _player.ballSocketPos; } //RHand _player.rHandLocalPos = GetNodePosition(SampleNode.RHand); _player.rHandPos = _player.TransformNodePosition(SampleNode.RHand, _player.rHandLocalPos); //Pelvis _player.pelvisLocalPos = GetNodePosition(SampleNode.Pelvis); _player.pelvisPos = _player.TransformNodePosition(SampleNode.Pelvis, _player.pelvisLocalPos); }
override public void OnEnter(AIState lastState) { uint skillID = 0; uint actionID = 0; Player defender = m_player.m_defenseTarget; if (defender != null) { bool hasLeftDefender = false, hasRightDefender = false, hasOuterDefender = false; IM.Vector3 dirPlayer2Basket = GameUtils.HorizonalNormalized(m_match.mCurScene.mBasket.m_vShootTarget, m_player.position); IM.Number fAngle = IM.Vector3.FromToAngle(dirPlayer2Basket, IM.Vector3.forward); IM.Quaternion rot = IM.Quaternion.Euler(IM.Number.zero, fAngle, IM.Number.zero); foreach (Player player in defender.m_team.members) { IM.Vector3 vecPlayer2Defender = player.position - m_player.position; IM.Vector3 dirPlayer2Defender = rot * vecPlayer2Defender.normalized; vecPlayer2Defender = dirPlayer2Defender * vecPlayer2Defender.magnitude; if (0 < vecPlayer2Defender.z && vecPlayer2Defender.z < new IM.Number(1, 500)) { if (new IM.Number(0, 800) < vecPlayer2Defender.x && vecPlayer2Defender.x < 2) { hasRightDefender = true; } if (-2 < vecPlayer2Defender.x && vecPlayer2Defender.x < -new IM.Number(0, 800)) { hasLeftDefender = true; } } if (m_player.m_AOD.GetStateByPos(player.position) == AOD.Zone.eValid) { hasOuterDefender = true; } } if (hasRightDefender) { skillID = DRIFT_SHOOT_ID; actionID = LEFT_ACTION_ID; Debug.Log("AIShoot, left drift shoot."); } else if (hasLeftDefender) { skillID = DRIFT_SHOOT_ID; actionID = RIGHT_ACTION_ID; Debug.Log("AIShoot, right drift shoot."); } else if (hasOuterDefender) { skillID = BACK_SHOOT_ID; Debug.Log("AIShoot, back shoot."); } } m_player.m_toSkillInstance = m_player.m_skillSystem.GetValidSkillInMatch(Command.Shoot, true, (skillInstance) => { return(skillID == 0 || skillInstance.skill.id == skillID); }); if (m_player.m_toSkillInstance != null) { if (actionID != 0) { m_player.m_toSkillInstance.curActionId = actionID; } } else if (skillID != 0) { Debug.Log("AIShoot, get shoot skill without filter."); m_player.m_toSkillInstance = m_player.m_skillSystem.GetValidSkillInMatch(Command.Shoot, true); } if (m_player.m_toSkillInstance == null) { Debug.LogWarning("AISkillSystem(" + m_player.m_id + "), no skill for AI Shoot"); } m_player.m_bForceShoot = true; }