public void Update() { NavMeshHit hit; m_isTargetObscured = m_agent.Raycast(Target, out hit); if (m_isTargetObscured && !m_linecasterRunning) { // If the target is not within line-of-sight and the line caster isn't running, start it up m_linecaster = StartCoroutine(CheckLinecast()); } else if (!m_isTargetObscured && m_linecasterRunning) { // If the target is within line-of-sight, stop the line caster and just beeline to the target m_linecasterRunning = false; m_usePathfinding = false; m_agent.ResetPath(); StopCoroutine(m_linecaster); } else if (!m_isTargetObscured) { // If target isn't obscured, beeline to target m_agent.ResetPath(); m_linecasterRunning = false; m_usePathfinding = false; } if (!m_usePathfinding) { NavMesh.SamplePosition(Target, out hit, m_agent.height, NavMesh.AllAreas); Vector3 dp = hit.position - transform.position; Vector3 direction = dp.normalized; Vector3 move = direction * m_agent.speed * Time.deltaTime; dest = hit.position; //if (dp.sqrMagnitude < move.sqrMagnitude) { // m_motion.Move(dp); //} else { m_motion.Move(move); //} dip = dp.magnitude; if (RotateToMovement && dp.magnitude > ROTATE_TO_MOVE_THRESHOLD) { Quaternion rot = Quaternion.LookRotation(Vector3.ProjectOnPlane(direction, Vector3.up), Vector3.up); Quaternion newRotation = Quaternion.Lerp(transform.rotation, rot, 10f * Time.deltaTime); transform.rotation = newRotation; } } }
private IEnumerator Flurry() { m_isFlurrying = true; m_motor.Movement = PlayerMotor.MovementStyle.Lock; Quaternion rotation = m_aim.Rotation; // Fire bullets with a time delay while (m_canFlurry) { FireQuickBolt(rotation); m_motion.Move(rotation * (Vector3.forward * 5f * Time.deltaTime)); yield return(new WaitForSeconds(QuickBoltDelay)); } m_isFlurrying = false; IsFinished = true; }
public Vector3 Move(Vector2 axes, float speed, bool turnToMotion = false, float turnSmoothing = DEFAULT_TURN_SMOOTHING) { Vector3 direction = ControlPlane.Transform(axes); Vector3 velocity = direction * speed * Time.deltaTime; if (m_motion.enabled) { m_motion.Move(velocity); } if (turnToMotion) { RotateTo(direction); } return(velocity); }
private IEnumerator ProcessLaunch(Vector3 initialVelocity, float deceleration, int bounces = -1) { Vector3 velocity = initialVelocity; float speed = velocity.magnitude; while (speed > 0f) { float dt = Time.deltaTime; if (m_motion.enabled) { NavMeshHit hit; bool collision = m_motion.Agent.Raycast(transform.position + velocity * dt, out hit); if (collision) { if (bounces != 0) { Vector3 reflection = Vector3.Reflect(velocity, hit.normal); bounces--; if (Bounced != null) { Bounced(this, new BounceEventArgs { Incident = velocity, Normal = hit.normal, Reflection = reflection }); } velocity = reflection; } } m_motion.Move(velocity * dt); } speed -= deceleration * dt; velocity -= deceleration * dt * velocity.normalized; yield return(null); } IsLaunched = false; }
public void Update() { if (m_speed > 0f) { Vector3 offset = m_endRotation * (m_speed * Time.deltaTime * Vector3.forward); NavMeshHit hit; bool hasHit = m_motion.Agent.Raycast(transform.position + offset, out hit); if (!hasHit || Vector3.Angle(-offset, hit.normal) >= GlancingAngleThreshold) { if (!m_isCharging) { float newSpeed = m_speed - (Friction * Time.deltaTime * Time.deltaTime); m_speed = Mathf.Clamp(newSpeed, 0f, MaxChargeSpeed); } m_motion.Move(offset); } else if (m_speed > CrashSpeedThreshold) { // EXPLOOOSION Vector3 reflection = Vector3.Reflect(offset.normalized, hit.normal); m_launchable.Launch(reflection * m_speed * RecoilElasticity, Friction); m_motor.enabled = true; m_isCharging = false; m_speed = 0f; } else { m_motor.enabled = true; m_isCharging = false; m_speed = 0f; } } }