Search Unity

Showcase app..

Discussion in 'Scripting' started by robertseadog, Oct 20, 2005.

  1. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    ok im making a showcase app for showing production models around to view glitches etc.. I have this code but it doesn't seem to work:


    Code (csharp):
    1. var isrotate = false;
    2.  
    3. function Update () {
    4. //transform.Rotate (0, 50 * Time.deltaTime ,0);
    5.     if (isrotate) {
    6.     transform.Rotate ((Input.GetAxis ("Vertical") * 50) * Time.deltaTime,(Input.GetAxis ("Horizontal") * 50) * Time.deltaTime, 0);
    7.     }
    8. }
    9. function OnMouseEnter () {
    10. }
    11. function OnMouseDown () {
    12. isrotate = true;
    13. }
    14. function OnMouseUp () {
    15. isrotate = false;
    16. }
    Whats wrong?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Not quite sure what you want to do but, your code will:

    Rotate the object the script is attached to, when the arrow keys are pressed and the mouse is over the collider of the object and the mouse is pressed down.
     
  3. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    Yea that was entirely wrong :D I made this which works but I want the value to be reverse, how do I do this?

    Code (csharp):
    1. var isrotate = false;
    2.  
    3. function Update () {
    4. //transform.Rotate (0, 50 * Time.deltaTime ,0);
    5.     if (isrotate == true) {
    6.     transform.Rotate ((Input.GetAxis ("up") * 10) * Time.deltaTime, (Input.GetAxis ("side") * 10) * Time.deltaTime, 0);
    7.     }
    8. }
    9.  
    10. function OnMouseDown () {
    11. isrotate = true;
    12. }
    13. function OnMouseUp () {
    14. isrotate = false;
    15. }
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    You mean rotate in the other direction?

    Multiply by -10 instead of 10?
     
  5. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    the up and sides are x and y values of the mouse position so you can rotate the model around at will, looking at what you want on the model..
     
  6. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    right now when you drag to the left it rotates to the right, which is not intuitive you know?
     
  7. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    Yea thats it.. why didn't I think of that :D
     
  8. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Then just flip the sign before passing the value to transform.Rotate
     
  9. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    ok thats better, but now im missing some movement here.. I think I need some movement in the z axis?
     
  10. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Maybe you want to use RotateAround instead?
     
  11. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    mm, that might work out better thanks! You mean using rotatearound the obj on the camera right? Im trying that! ;)
     
  12. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    Hmm I can't get it to move in two(3) axes!

    Code (csharp):
    1.  
    2. var isrotate = false;
    3. var cam : Transform;
    4.  
    5. function Update () {
    6.     if (isrotate == true) {
    7.  
    8.     cam.RotateAround (transform.position, Vector3.up, (Input.GetAxis ("side") * 20) * Time.smoothDeltaTime );
    9.    
    10.  
    11. // (Input.GetAxis ("up") * 20) * Time.smoothDeltaTime
    12.     }
    13. }
    14.  
    15. function OnMouseDown () {
    16. isrotate = true;
    17. }
    18. function OnMouseUp () {
    19. isrotate = false;
    20. }
    21.  
     
  13. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    You have to call RotateAround 2 times. Where you rotate around 2 different axes.
     
  14. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    ok, one more thing:

    It would be really cool if the Vector was oriented after the world values, because now when I turn the obj the controlls reverse!
     
  15. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    You can always use transform.TransformDirection to go from local world space.