private void Start() { if (instance == null) { instance = this; } else { Destroy(gameObject); } MovementSM = new StateMachine(); Standing = new StandingState(this, MovementSM); Fly = new FlyState(this, MovementSM); Swing = new SwingState(this, MovementSM); Create = new CreateState(this, MovementSM); Transition = new TransitionState(this, MovementSM); ActivCube = CubePrefabs[0]; MovementSM.Initialize(Create); Platform = GameObject.FindGameObjectWithTag("Platform"); LastBlock = Platform; }
// Start is called before the first frame update void Start() { prepStart = Time.time; swingState = SwingState.PREPING; rb = GetComponent <Rigidbody>(); hinge = GetComponent <HingeJoint>(); }
// Update is called once per frame void Update() { switch (swingState) { case SwingState.PREPING: if (Time.time - prepStart > 3f) { swingState = SwingState.SWINGING; hinge.useSpring = true; hinge.useMotor = false; rb.isKinematic = false; } break; case SwingState.SWINGING: if (hinge.angle < -140) { Debug.Log("Upswing."); swingState = SwingState.UPSWING; hinge.useSpring = false; hinge.useMotor = true; } break; case SwingState.UPSWING: if (hinge.angle > -2f) { swingState = SwingState.PREPING; rb.isKinematic = true; } break; } }
private void ResetSwing() { power = 0; accuracy = 0; powerTickerRect.position = new Vector3(powerBarStartX, powerTickerRect.position.y); currentState = SwingState.None; accuracyTicker.enabled = false; }
private void NoPowerSet() { powerTickerRect.Translate(-500.0f * Time.deltaTime, 0f, 0f); if (powerTickerRect.position.x <= powerBarStartX) { powerTickerRect.position = new Vector3(powerBarStartX, powerTickerRect.position.y); currentState = SwingState.None; } }
private void moveAccuracyTicker() { accuracyTickerRect.Translate(400.0f * Time.deltaTime, 0f, 0f); // This value is not negative because the model has been flipped 180 degrees if (accuracyTickerRect.position.x <= accuracyTickerEndPoint) { accuracy = 20; currentState = SwingState.Travel; } }
private void movePowerTicker() { powerTickerRect.Translate(400.0f * Time.deltaTime, 0f, 0f); if (powerTickerRect.position.x >= powerBarEndX) { currentState = SwingState.NoPowerSet; NoPowerSet(); } }
public override PlayerState FixedUpdate(float delta) { base.FixedUpdate(delta); if ((!animation.IsPlaying() && !Input.IsActionPressed("CommandLamp")) || timer > 0.75) { AttackState a = new SwingState(); a.Damage = Damage + (int)(50 * timer / 0.75f); a.KnockBack = KnockBack + (int)(20 * timer / 0.75f); return(a); } timer += delta; return(null); }
protected override Validation <string, MeleeToolConfiguration> CreateService( string key, string slot, Set <string> additionalSlots, Set <string> tags, ILoggerFactory loggerFactory) { return (from swingAnimation in Optional(SwingAnimation) .ToValidation("Missing swing animation.") from statesPath in StatesPath.TrimToOption() .ToValidation("Missing animation state machine path.") from seekerPath in SeekerPath.TrimToOption() .ToValidation("Missing seekable animator path.") from playerControl in PlayerControl .ToValidation("Failed to find the player control.") from idleState in IdleState.TrimToOption() .ToValidation("Idle state value was not specified.") from swingState in SwingState.TrimToOption() .ToValidation("Swing state value was not specified.") select new MeleeToolConfiguration( key, slot, additionalSlots, tags, ArmInput, SwingInput, swingAnimation, statesPath, seekerPath, idleState, swingState, new Range <float>(Max(MinPosition, 0), Max(MaxPosition, 0), TFloat.Inst), playerControl, Active, loggerFactory) { Mesh = Mesh, EquipAnimation = EquipAnimation, UnequipAnimation = UnequipAnimation, Animation = Animation, AnimationBlend = AnimationBlend, AnimationTransition = AnimationTransition }); }
//Every phys tick void FixedUpdate() { //If state is neutral, do nothing if (swingState != SwingState.NONE) { //Update rotation Vector3 axis = Vector3.up * (short)myDirection; float angle = speed * (short)swingState * Time.fixedDeltaTime; door.transform.RotateAround(transform.position, axis, angle); //Grab new Y value float currentAngle = door.transform.localRotation.eulerAngles.y; //If rotation is completed //This comparison works for both open & close because Unity's angles wrap (359<->0) if ((myDirection == DoorDirection.CLOCKWISE && currentAngle > maxAngle) || (myDirection == DoorDirection.ANTI_CLOCKWISE && currentAngle < maxAngle)) { //Set door to a completed state doorState = (DoorState)swingState; swingState = SwingState.NONE; //Snap door to absolute correct angle for end of current rotation float snapX = door.transform.localRotation.eulerAngles.x; float snapY = 0; float snapZ = door.transform.localRotation.eulerAngles.z; if (doorState == DoorState.OPEN) { snapY = maxAngle; } if (doorState == DoorState.CLOSED) { snapY = 0; } door.transform.localRotation.eulerAngles.Set(snapX, snapY, snapZ); } else { //Debug.Log(currentAngle); } } }
void Update() { if (GameManager.CurrentGameState == GameManager.GameState.Unstarted || GameManager.CurrentGameState == GameManager.GameState.Paused || m_ignoreInput || PlayerManager.IsRolling) { m_currentSwingState = SwingState.Unstarted; return; } if (m_cam == null && Camera.main != null) { m_cam = Camera.main.transform; } if (m_ballRigidBody == null) { GameObject ball = GameObject.FindGameObjectWithTag ("Player"); if (ball != null) { m_ballRigidBody = GameObject.FindGameObjectWithTag ("Player").GetComponent<Rigidbody> (); } } else { m_currentSwingState = SetCurrentSwingState (); } }
public void Advance() { if (swingDuration > Game.TIMESTEP) { hilt.gameObject.SetActive(true); swingDuration -= Game.TIMESTEP; FInt pct = swingDuration / maxDuration; switch (state) { case SwingState.STAB: position.x = 150 * (new FInt(1L) - pct) * FInt.Cos(angle + FInt.PI / 2); position.y = new FInt(61) + 150 * (new FInt(1L) - pct) * FInt.Sin(angle + FInt.PI / 2); rotation = angle; break; case SwingState.CWISE: position.x = 150 * FInt.Cos(angle + (new FInt(2) - pct) * FInt.PI / 2); position.y = new FInt(61) + 150 * FInt.Sin(angle + (new FInt(2) - pct) * FInt.PI / 2); rotation = angle + (-pct + 1) * FInt.PI / 2; break; case SwingState.CCWISE: position.x = 150 * FInt.Cos(angle + pct * FInt.PI / 2); position.y = new FInt(61) + 150 * FInt.Sin(angle + pct * FInt.PI / 2); rotation = angle - (-pct + 1) * FInt.PI / 2; break; } transform.localPosition = new Vector3(position.x.ToFloat(), position.y.ToFloat()); transform.localEulerAngles = new Vector3(0, 0, rotation.ToFloat() * 180 / Mathf.PI); hilt.position = position; CheckCollisions(); } else { hilt.gameObject.SetActive(false); if (swingCooldown > 0L) { swingCooldown -= Game.TIMESTEP; } else { state = SwingState.NONE; } } }
public void Close() => swingState = SwingState.CLOSING;
//Shorthand EBDs public void Open() => swingState = SwingState.OPENING;
private void LaunchBall() { _ballMovementHandler.SetAttributes(power, accuracy); Debug.Log("Power: " + power + " Accuracy: " + accuracy); currentState = SwingState.Reset; }
void FixedUpdate() { if (m_currentSwingState != SwingState.Started) { m_arrow.SetActive (false); m_crumbOne.SetActive (false); m_crumbTwo.SetActive (false); } if (m_cam == null || m_ballRigidBody == null) return; if (m_currentSwingState == SwingState.Ended) { float velocity = (Vector3.Distance (m_swingInputStartPosition, m_swingInputEndPosition) * 4.0f) / (0.25f * Screen.height); if (velocity > 6.0f) { velocity = 6.0f; } m_camForward = Vector3.Scale (m_cam.forward, new Vector3 (1, 0, 1)); m_move = (m_swingInputDirection.z * m_camForward + m_swingInputDirection.x * m_cam.right); m_ballRigidBody.AddForce (m_move * velocity); m_currentSwingState = SwingState.Unstarted; PlayerManager.SetRollState (true); PlayerManager.IncrementHits (); PowerBar.SetFill (m_ballRigidBody.velocity.magnitude / 6.0f); } else if (m_currentSwingState == SwingState.Started) { Vector3 currPos = Input.mousePosition; Vector3 rawDirection = m_swingInputStartPosition - currPos; Vector3 swingInputDir = new Vector3 (rawDirection.x, 0.0f, rawDirection.y); float velocity = Vector3.Distance (m_swingInputStartPosition, currPos) / (0.25f * Screen.height); if (velocity > 6.0f) { velocity = 6.0f; } Vector3 camForward = Vector3.Scale (m_cam.forward, new Vector3 (1, 0, 1)); Vector3 moveVector = (swingInputDir.z * camForward + swingInputDir.x * m_cam.right); Vector3 target = PlayerManager.Ball.transform.position + moveVector.normalized; target.y += 0.02f; m_arrow.transform.position = target; target = PlayerManager.Ball.transform.position + (moveVector.normalized * 0.67f); target.y += 0.02f; m_crumbOne.transform.position = target; target = PlayerManager.Ball.transform.position + (moveVector.normalized * 0.33f); target.y += 0.02f; m_crumbTwo.transform.position = target; m_crumbTwo.transform.LookAt (m_arrow.transform.position); m_crumbOne.transform.LookAt (m_arrow.transform.position); target = m_arrow.transform.position; target = PlayerManager.Ball.transform.position + (moveVector.normalized * 1.33f); target.y += 0.02f; m_arrow.transform.LookAt (target); m_arrow.SetActive (true); m_crumbOne.SetActive (true); m_crumbTwo.SetActive (true); PowerBar.SetFill (velocity / 6.0f); } else { PowerBar.SetFill (m_ballRigidBody.velocity.magnitude / 6.0f); } }
public void Swing(SwingState swingType, FInt swingAngle) { if (state != SwingState.NONE) { return; } state = swingType; swingDuration = new FInt(0.1f) + new FInt(0.025f) * weight; maxDuration = swingDuration; swingCooldown = new FInt(0.1f) + new FInt(0.01f) * weight; switch (state) { case SwingState.STAB: angle = swingAngle - FInt.PI / 2; break; case SwingState.CWISE: angle = swingAngle - FInt.PI; break; case SwingState.CCWISE: angle = swingAngle; break; } }
void Start() { if (Instance == null) { Instance = this; } m_currentSwingState = SwingState.Unstarted; m_arrow = GameObject.Instantiate (m_arrowPrefab); m_arrow.transform.localScale = m_arrow.transform.localScale * 0.6f; m_crumbOne = GameObject.Instantiate (m_arrowPrefab); m_crumbOne.transform.localScale = m_crumbOne.transform.localScale * 0.8f; m_crumbTwo = GameObject.Instantiate (m_arrowPrefab); m_crumbTwo.transform.localScale = m_crumbTwo.transform.localScale * 1.0f; }