Exemple #1
0
 private void ApplyNonUnitySolver()
 {
     // example index 0, 1 are input and 2..7 are transform outputs
     // there is no example fmu for this
     RB.MovePosition(new Vector3((float)fmu.GetReal(FMUData.modelVariables[2].name),
                                 (float)fmu.GetReal(FMUData.modelVariables[3].name),
                                 (float)fmu.GetReal(FMUData.modelVariables[4].name)));
     RB.MoveRotation(Quaternion.Euler(new Vector3((float)fmu.GetReal(FMUData.modelVariables[5].name),
                                                  (float)fmu.GetReal(FMUData.modelVariables[6].name),
                                                  (float)fmu.GetReal(FMUData.modelVariables[7].name))));
 }
    /// <summary>
    /// Rotates the player based on current input
    /// </summary>
    void Rotate()
    {
        if (m_inputVector == Vector3.zero)
        {
            return;
        }

        float targetAngle = Mathf.Atan2(m_inputVector.x, m_inputVector.z) * Mathf.Rad2Deg;

        m_smoothAngle = Mathf.LerpAngle(m_smoothAngle, targetAngle, m_rotationSpeed * Time.deltaTime);
        RB.MoveRotation(Quaternion.Euler(Vector3.up * m_smoothAngle));
    }
    /// <summary>
    /// Moves the look at target to where the mouse is
    /// </summary>
    public void LookAtMouse()
    {
        Ray        camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(camRay, out hit, m_rayCastDistance, m_floorLayerMask))
        {
            Vector3 dir = hit.point - RB.position;
            dir.y = 0f;

            Quaternion targetRotation = Quaternion.LookRotation(dir);
            RB.MoveRotation(targetRotation);
        }
    }
        public void Animate()
        {
            Vector3    pos = transform.position;
            Quaternion rot = RB.rotation;
            float      s   = StrengthAtDistance.Evaluate(math.distance(Cached.Position, pos) / Radius);
            Vector3    f   = math.normalize((Cached.Position - pos)) * s * Time.deltaTime * Strength;

            if (f.magnitude > 0f)
            {
                RB.AddForce(f);
            }

            quaternion r = Quaternion.Slerp(RB.rotation, Cached.Rotation, s * Time.deltaTime * Strength);

            RB.MoveRotation(r);
        }
Exemple #5
0
 public void ForceReset(Vector3 pos, Quaternion rot)
 {
     RB.MovePosition(pos);
     RB.MoveRotation(rot);
     RB.velocity        = Vector3.zero;
     RB.angularVelocity = Vector3.zero;
     CurrentGear        = 1;
     CurrentRPM         = 0f;
     CurrentSpeed       = 0f;
     currentTorque      = 0f;
     AccellInput        = 0f;
     SteerInput         = 0f;
     foreach (var axle in axles)
     {
         axle.wheel.brakeTorque = Mathf.Infinity;
         axle.wheel.motorTorque = 0f;
     }
 }
Exemple #6
0
    public bool ForceReset(Vector3 pos, Quaternion rot)
    {
        RB.MovePosition(pos);
        RB.MoveRotation(rot);
        RB.velocity        = Vector3.zero;
        RB.angularVelocity = Vector3.zero;
        CurrentGear        = 1;
        CurrentRPM         = 0f;
        AccellInput        = 0f;
        SteerInput         = 0f;

        foreach (var axle in Axles)
        {
            axle.Left.brakeTorque  = Mathf.Infinity;
            axle.Right.brakeTorque = Mathf.Infinity;
            axle.Left.motorTorque  = 0f;
            axle.Right.motorTorque = 0f;
        }
        return(true);
    }
    private void PEDTurn()
    {
        if (controller.CurrentTurn != Vector3.zero)
        {
            RB.MoveRotation(Quaternion.Slerp(RB.rotation, Quaternion.LookRotation(controller.CurrentTurn), AngularSpeed * Time.fixedDeltaTime));
        }
        else
        {
            RB.angularVelocity = Vector3.zero;
        }

        var euler1 = LastRBRotation.eulerAngles;
        var euler2 = RB.rotation.eulerAngles;
        var diff   = euler2 - euler1;

        for (int i = 0; i < 3; i++)
        {
            diff[i] = (diff[i] + 180) % 360 - 180;
        }
        controller.CurrentAngularVelocity = diff / Time.fixedDeltaTime * Mathf.Deg2Rad;
    }