Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[SOLVED] Can't rotate object with script

Discussion in 'Scripting' started by clawd31, Mar 4, 2016.

  1. clawd31

    clawd31

    Joined:
    Aug 5, 2013
    Posts:
    26
    Hello, i have a problem with one of my script.
    I'm trying to make closable/openable doors. Everything works except one thing: Only the Collider rotate, the model of the door don't move :/

    Code (JavaScript):
    1. var smooth : float = 2.0f;
    2. var DoorOpenAngle : float = 90.0f;
    3. var DoorCloseAngle : float = 0.0f;
    4. var open : boolean;
    5. var enter : boolean;
    6. var OpenDoorSound : AudioClip;
    7. var ASource : AudioSource;
    8.  
    9. function Update() {
    10.     if (open == true) {
    11.         var target = Quaternion.Euler (0, DoorOpenAngle, 0);
    12.         transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
    13.     } else {
    14.         var target1 = Quaternion.Euler (0, DoorCloseAngle, 0);
    15.         transform.rotation = Quaternion.Slerp(transform.rotation, target1, Time.deltaTime * smooth);
    16.     }
    17.     if (enter == true && Input.GetKeyDown("f")) {
    18.         open = !open;
    19.         ASource.PlayOneShot(OpenDoorSound, 0.7F);
    20.     }
    21. }
    22. function OnTriggerStay(other : Collider) {
    23.     if (other.gameObject.tag == "Player") {
    24.         enter = true;
    25.     }
    26. }
    27. function OnTriggerExit(other : Collider) {
    28.     if (other.gameObject.tag == "Player") {
    29.         enter = false;
    30.     }
    31. }
    Before the player open the door:


    After pressing 'F', only the boxes move not the model:


    Can someone help me please ? :D
     
  2. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    Is your object marked as "static" by any chance?
     
    jitterware and aihodge like this.
  3. clawd31

    clawd31

    Joined:
    Aug 5, 2013
    Posts:
    26
    omg, i feel so dumb right now o_O

    Ty for your help ! :D
     
  4. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    Your welcome.