/* * This method is what turns the vehicles about the y axis * turn is the player input * speed is a constant defined for a particular vehicle */ void TurnRotate(float turn, float speed) { if (StateManager.curState == 3) { //transform.RotateAround (transform.position, transform.up, turn * speed / 5); Rb.AddTorque(inverseTrap * transform.up * turn * speed * 40); } }
void FixedUpdate() { // Gets input from player. Vector2 moveInput = GetMoveInput(); // As the player can't move backwards, // the y-component of the input is clamped between [0, inf] moveInput.y = Mathf.Max(0f, moveInput.y); // If the player is signaling to accelerate, // the back burner graphic should appear. if (moveInput.y > 0f) { animator.SetBool("Boosting", true); } // Otherwise it shouldn't. else { animator.SetBool("Boosting", false); } // Calculate and apply forces. float tourque = -moveInput.x * turnSpeed * Time.fixedDeltaTime; Rb.AddTorque(tourque); float forwardForce = moveInput.y * moveSpeed * Time.fixedDeltaTime; Rb.AddForce(forwardForce * transform.right); // To ensure the player can't move too fast, // the drag increases along with the velociy of the player. Rb.drag = Rb.velocity.magnitude * linearDragRate + linearDragMinimum; // Same applies for angular drag. Rb.angularDrag = Mathf.Abs(Rb.angularVelocity) * angularDragRate + angularDragMinimum; Debug.Log(string.Format("Velocity: {0}, Speed, {1}, Torque: {2}, Health: {3}.", Rb.velocity, Rb.velocity.magnitude, Rb.angularVelocity, Health)); }
void Move() { Vector3 WheelDir = Vector3.zero; if (Input.GetKey(UpKey) || Input.GetKey(DownKey)) { WheelDir = Vector3.zero; if (Input.GetKey(UpKey)) { WheelDir = transform.up; } if (Input.GetKey(DownKey)) { WheelDir = -transform.up; } if (Input.GetKey(UpKey) && Input.GetKey(DownKey)) { WheelDir = Vector3.zero; } } Rb.AddTorque(-WheelDir * Force, ForceMode.Impulse); }
public void AddTorque(Vector3 force) { Rb.AddTorque(force); }
protected override void HandlePhysics() { Vector3 wantedTorque = Vector3.up * TorqueSpeed; Rb.AddTorque(wantedTorque); }