private bool UpdateOffMeshLink(IRobotPlayerWapper robot, ref Vector3 velocity, ref Quaternion lookRotation) { // Ignore the y difference when determining a look direction and velocity. // This will give XZ distances a greater impact when normalized. var direction = robot.NavMeshAgent.currentOffMeshLinkData.endPos - robot.Entity.position.Value; var jumpY = direction.y; direction.y = 0; lookRotation = Quaternion.LookRotation(direction); if (direction.sqrMagnitude > 0.1f || robot.Entity.playerMove.IsGround) { if (jumpY > robot.RobotSpeedInfo.JumpMaxHeight) { return(false); } else { var l = 2 * robot.RobotSpeedInfo.JumpMaxHeight - jumpY; velocity = (direction.magnitude + 0.5f) / GetTimeByJumpDist(robot, l) * direction.normalized; velocity.y = 0; return(true); } } return(false); }
public override void OnAwake() { base.OnAwake(); m_PositiveAngle = Random.value < 0.5f; mEntity = GetComponent <EntityReference>().Reference as PlayerEntity; wapper = mEntity.robot.Wapper; }
private float GetTimeByJumpDist(IRobotPlayerWapper robot, float dist) { var delta = Mathf.Sqrt(robot.RobotSpeedInfo.JumpVo * robot.RobotSpeedInfo.JumpVo + dist * robot.RobotSpeedInfo.JumpAcceleration * robot.RobotSpeedInfo.JumpAcceleration); var t = (delta - robot.RobotSpeedInfo.JumpVo) / robot.RobotSpeedInfo.JumpAcceleration; return(t); }
public void OnRespawn(IRobotPlayerWapper robot) { // Reset the NavMeshAgent to the new position. robot.NavMeshAgent.Warp(robot.Entity.position.Value); if (robot.NavMeshAgent.isOnOffMeshLink) { robot.NavMeshAgent.ActivateCurrentOffMeshLink(false); } robot.NavMeshAgent.updateRotation = true; robot.NavMeshAgent.updatePosition = true; robot.NavMeshAgent.velocity = Vector3.zero; }
private void Run(IRobotPlayerWapper robot) { var velocity = Vector3.zero; robot.RobotUserCmdProvider.HasPath = false; robot.RobotUserCmdProvider.IsJump = false; robot.RobotUserCmdProvider.DesirwdVelocity = Vector3.zero; if (robot.NavMeshAgent.isOnOffMeshLink && robot.Entity.playerMove.IsGround && UpdateOffMeshLink(robot, ref velocity, ref lookRotation)) { robot.RobotUserCmdProvider.HasPath = true; lookRotation.SetLookRotation(velocity); robot.RobotUserCmdProvider.DesirwdVelocity = velocity; robot.RobotUserCmdProvider.IsJump = true; } else { // Only move if a path exists. if (!HasArrived() && robot.NavMeshAgent.path.corners.Length > 1) { var forward = robot.NavMeshAgent.path.corners[1] - robot.NavMeshAgent.path.corners[0]; forward.y = 0; lookRotation = Quaternion.LookRotation(forward); robot.RobotUserCmdProvider.HasPath = true; robot.RobotUserCmdProvider.DesirwdVelocity = forward; } } // Don't let the NavMeshAgent move the character - the robot.RobotUserCmdProvider can move it. robot.RobotUserCmdProvider.LookAt = lookRotation; //robot.NavMeshAgent.nextPosition = robot.Position; }
protected void OnGrounded(IRobotPlayerWapper robot, bool grounded) { if (grounded) { // The agent is no longer on an off mesh link if they just landed. if (robot.NavMeshAgent.isOnOffMeshLink) { robot.NavMeshAgent.CompleteOffMeshLink(); } // Warp the NavMeshAgent just in case the navmesh position doesn't match the transform position. var destination = robot.NavMeshAgent.destination; robot.NavMeshAgent.Warp(robot.Entity.position.Value); // Warp can change the destination so make sure that doesn't happen. if (robot.NavMeshAgent.destination != destination) { robot.NavMeshAgent.SetDestination(destination); } robot.NavMeshAgent.updateRotation = true; robot.NavMeshAgent.updatePosition = true; robot.NavMeshAgent.velocity = Vector3.zero; } }
/// <summary> /// Cache the component references and initialize the SharedFields. /// </summary> public override void OnAwake() { mEntity = GetComponent <EntityReference>().Reference as PlayerEntity; wapper = mEntity.robot.Wapper; }