private void Awake() { Instance = this; singleList = new List <Single>(); meshParticleSystem = GetComponent <MeshParticleSystem>(); if (!moveVelocity) { moveVelocity = GameObject.Find("Player").GetComponent <MoveVelocity>(); } }
private void SortMoves() { for (int i = 0; i < m_moveSpeed.Length - 1; i++) { for (int j = i + 1; j < m_moveSpeed.Length; j++) { if (m_moveSpeed[i].MovePriority < m_moveSpeed[j].MovePriority) { MoveVelocity moveVelocity = m_moveSpeed[i]; m_moveSpeed[i] = m_moveSpeed[j]; m_moveSpeed[j] = moveVelocity; } } } }
/* * Returns false if camera didn't move */ private bool ComputeCameraMovement() { var frameDurationFactor = (float)(App.Current.TimeSinceLastFrame) / FRAME_DURATION_AT_60_FPS; if (PositionDistance.Length() > STOP_DISTANCE_THRESHOLD || TargetDistance.Length() > STOP_DISTANCE_THRESHOLD || MoveVelocity.Length() > STOP_DISTANCE_THRESHOLD || _lookingAroundDelta.Length() > STOP_DISTANCE_THRESHOLD || _manipulatedByMouseWheel || _orbitDelta.Length() > 0.001f || _manipulatedByKeyboard) { if (_orbitDelta.Length() > 0.001f) { OrbitByAngle(_orbitDelta); _orbitDelta *= new Vector2(ORBIT_HORIZONTAL_FRICTION, ORBIT_VERTICAL_FRICTION) / frameDurationFactor; } if (MoveVelocity.Length() > MaxMoveVelocity) { MoveVelocity *= MaxMoveVelocity / MoveVelocity.Length(); } else if (!_manipulatedByKeyboard) { MoveVelocity *= (1 - _frictionKeyboardManipulation) / frameDurationFactor; } _cameraPositionGoal += MoveVelocity; _cameraTargetGoal += MoveVelocity + _lookingAroundDelta; _lookingAroundDelta = Vector3.Zero; PositionDistance *= CAMERA_MOVE_FRICTION / frameDurationFactor; TargetDistance *= CAMERA_MOVE_FRICTION / frameDurationFactor; _isTransitionActive = true; _manipulatedByMouseWheel = false; return(true); } else { StopTransitionOfPositionTarget(); _isTransitionActive = false; return(false); } }
private void Start() { if (!animControl) { animControl = GameObject.Find("Player").GetComponent <AnimationControl>(); } if (!moveVelocity) { moveVelocity = GameObject.Find("Player").GetComponent <MoveVelocity>(); } if (!playerShoot) { playerShoot = GameObject.Find("Player").GetComponent <Shoot>(); } playerShoot.OnShoot += PlayerShoot_OnShoot; }
//Moves the character based on the direction, and the speed based on the MoveMode. public void Move(Vector2 direction) { int moveIndex = 0; for (int i = 0; i < m_moveSpeed.Length; i++) { MoveVelocity moveSpeed = m_moveSpeed[i]; if (moveSpeed.Active(direction, IsGrounded)) { moveIndex = i; break; } } if (IsDashing) { if (direction.x > 0f) { direction.x = 1f; } else if (direction.x < 0f) { direction.x = -1f; } } Vector3 velocity = m_moveSpeed[moveIndex].GetVelocity(direction, m_rigidbody.velocity, ref m_acceleration); IsRegular = (m_moveSpeed[moveIndex].MoveMode == MoveMode.Run && direction.x != 0f); IsCrouching = (m_moveSpeed[moveIndex].MoveMode == MoveMode.Crouch); IsDashing = (m_moveSpeed[moveIndex].MoveMode == MoveMode.Dash && direction.x != 0f); Velocity = velocity; Rotate(direction.x, m_moveSpeed[moveIndex].RotationSpeed); m_rigidbody.AddForce(velocity, m_forceMode); }
public Single(Vector3 position, Vector3 direction, MeshParticleSystem meshParticleSystem, MoveVelocity moveVelocity) { this.position = position; this.direction = direction; this.meshParticleSystem = meshParticleSystem; if (moveVelocity.velocityVector.y == 0) { quadSize = new Vector3(.3f, .2f); } else { quadSize = new Vector3(.5f, .4f); } moveSpeed = Random.Range(3f, 4f); uvIndex = 0; uvIndexTimerMax = 1f / 20; quadIndex = meshParticleSystem.AddQuad(position, 0f, quadSize, true, uvIndex); }
private bool ManipulateCameraByKeyboard() { var frameDurationFactor = (float)(App.Current.TimeSinceLastFrame); Vector3 viewDir, sideDir, upDir; _showSceneControl.RenderSetup.CalcDirections(out viewDir, out sideDir, out upDir); var viewDirLength = viewDir.Length(); var initialVelocity = MoveVelocity.Length() < STOP_DISTANCE_THRESHOLD ? INITIAL_MOVE_VELOCITY : 0; var increaseAccelerationWithZoom = (_cameraPositionGoal - _cameraTargetGoal).Length() / 10f; var accelFactor = _cameraAcceleration * increaseAccelerationWithZoom; var interactionKeysPressedCount = 0; foreach (var key in _pressedKeys) { switch (key) { case Key.A: case Key.Left: MoveVelocity -= sideDir * (accelFactor + initialVelocity) * frameDurationFactor; interactionKeysPressedCount++; break; case Key.D: case Key.Right: MoveVelocity += sideDir * (accelFactor + initialVelocity) * frameDurationFactor; interactionKeysPressedCount++; break; case Key.W: case Key.Up: MoveVelocity += viewDir * (accelFactor + initialVelocity) / viewDirLength * frameDurationFactor; interactionKeysPressedCount++; break; case Key.S: case Key.Down: MoveVelocity -= viewDir * (accelFactor + initialVelocity) / viewDirLength * frameDurationFactor; interactionKeysPressedCount++; break; case Key.E: MoveVelocity += upDir * (accelFactor + initialVelocity) * frameDurationFactor; interactionKeysPressedCount++; break; case Key.X: MoveVelocity -= upDir * (accelFactor + initialVelocity) * frameDurationFactor; interactionKeysPressedCount++; break; case Key.F: MoveVelocity = Vector3.Zero; _cameraPositionGoal = new Vector3(0, 0, DEFAULT_CAMERA_POSITION_Z); _cameraTargetGoal = new Vector3(0, 0, 0f); interactionKeysPressedCount++; break; // Center Camera case Key.C: var delta = _showSceneControl.RenderSetup.TransformGizmo.IsGizmoActive ? _showSceneControl.RenderSetup.TransformGizmo.GizmoToWorld.TranslationVector - _cameraTargetGoal : -_cameraTargetGoal; _cameraTargetGoal += delta; _cameraPositionGoal += delta; interactionKeysPressedCount++; break; } } return(interactionKeysPressedCount > 0); }
private void Awake() { _moveVelocity = GetComponent <MoveVelocity>(); }