Search Unity

living body rotation

Discussion in 'Scripting' started by Trild123787898, Jan 18, 2020.

  1. Trild123787898

    Trild123787898

    Joined:
    Dec 9, 2018
    Posts:
    206
    how can I change the script so that I can rotate the object with the rigidbody component ?
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5.  
    6. public class mehanic : MonoBehaviour
    7. {
    8.     public Transform detail1;
    9.     public Transform detail2;
    10.     public Transform detail3;
    11.    
    12.  
    13.  
    14.  
    15.  
    16.  
    17.     void FixedUpdate()
    18.     {
    19.  
    20.         if (Input.GetKey(KeyCode.E))
    21.         {
    22.             //hinge.GetComponent(ConfigurableJoint).lowAngularXLimit = 10f;
    23.  
    24.             detail1.localRotation = Quaternion.RotateTowards(detail1.localRotation, Quaternion.Euler(new Vector3(30, 0, 0)), 20f * Time.deltaTime);
    25.  
    26.  
    27.         }
    28.         if (Input.GetKey(KeyCode.Q))
    29.         {
    30.  
    31.             detail1.localRotation = Quaternion.RotateTowards(detail1.localRotation, Quaternion.Euler(new Vector3(-30, 0, 0)), 20f * Time.deltaTime);
    32.  
    33.  
    34.         }
    35.         if (Input.GetKey(KeyCode.Y))
    36.         {
    37.  
    38.  
    39.             detail2.localRotation = Quaternion.RotateTowards(detail2.localRotation, Quaternion.Euler(new Vector3(44, 0, 0)), 20f * Time.deltaTime);
    40.  
    41.  
    42.  
    43.         }
    44.         if (Input.GetKey(KeyCode.U))
    45.         {
    46.  
    47.  
    48.             detail2.localRotation = Quaternion.RotateTowards(detail2.localRotation, Quaternion.Euler(new Vector3(-21, 0, 0)), 20f * Time.deltaTime);
    49.  
    50.         }
    51.         if (Input.GetKey(KeyCode.N))
    52.         {
    53.  
    54.  
    55.             detail3.localRotation = Quaternion.RotateTowards(detail3.localRotation, Quaternion.Euler(new Vector3(40, 0, 0)), 20f * Time.deltaTime);
    56.  
    57.  
    58.  
    59.         }
    60.         if (Input.GetKey(KeyCode.M))
    61.         {
    62.  
    63.  
    64.             detail3.localRotation = Quaternion.RotateTowards(detail3.localRotation, Quaternion.Euler(new Vector3(-40, 0, 0)), 20f * Time.deltaTime);
    65.  
    66.         }
    67.     }
    68. }
    69.  
     
    Last edited: Jan 18, 2020
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    What object with a rigidbody component? You are only referencing transforms. Do the transforms have a parent with a rigidbody? You provide too little information for me to give you any proper answer.
     
  3. Trild123787898

    Trild123787898

    Joined:
    Dec 9, 2018
    Posts:
    206
    I have an object that I manage with the help of this script, but at the same time I use joins, but for this I need and I used the iskinematic checkbox, but this is the result of which I need to, can I set the same rotation of the object according to the given axis when using rigidbody?