Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Rotating a Transform in Tiny (SOLVED!)

Discussion in 'Project Tiny' started by RamonDevs, Jan 23, 2019.

  1. RamonDevs

    RamonDevs

    Joined:
    Apr 11, 2015
    Posts:
    13
    I'm using a very simple function to attempt rotation.
    Code (JavaScript):
    1.   RotationDependingOnMovement(movement: Vector3): Euler
    2.         {
    3.             let resultingRotation = new Euler(0, 0, 0);
    4.             if (movement.x > 0 && movement.y == 0) resultingRotation.z = 0;
    5.             if (movement.x < 0 && movement.y == 0) resultingRotation.z = 180;
    6.             if (movement.x == 0 && movement.y > 0) resultingRotation.z = 90;
    7.             if (movement.x == 0 && movement.y > 0) resultingRotation.z = 270;
    8.             if (movement.x > 0 && movement.y > 0) resultingRotation.z = 45;
    9.             if (movement.x > 0 && movement.y < 0) resultingRotation.z = -45;
    10.             if (movement.x < 0 && movement.y > 0) resultingRotation.z = 135;
    11.             if (movement.x < 0 && movement.y < 0) resultingRotation.z = 225;
    12.             return resultingRotation;
    13.         }
    14.  
    Then I attempt to set the rotation using:
    Code (JavaScript):
    1.                     rotation.rotation.setFromEuler(this.RotationDependingOnMovement(move));
    2.  
    I have no idea why this doesn't work. The console log says 0,0,0 all the time, even when I'm moving the object correctly with that same Move vector3, and the RotationDependingOnMovement function returns the expected values.

    Thanks for your help! (also there are 0 examples of rotation, which is quite weird)

    For anyone looking at this in the future, the issue is you MUST do:

    rotation.rotation = rotation.rotation.setFromEuler(whateverEuler) , which makes no sense, why would you call it "setFromEuler" if it doesn't... SET the rotation?
     
    Last edited: Jan 24, 2019
    Adrian-Anta likes this.
  2. tomny

    tomny

    Joined:
    Sep 12, 2015
    Posts:
    16
    is rotation a Component?
    if youre doing something like this
    Code (JavaScript):
    1. let resultManager = this.world.getComponentData(this.world.getEntityByName("ResultManager"), game.ResultController);
    2. resultManager.result = x;
    3.  
    then u need to make sure you set the component data like so
    Code (JavaScript):
    1. this.world.setComponentData(this.world.getEntityByName("ResultManager"), resultManager);
     
  3. RamonDevs

    RamonDevs

    Joined:
    Apr 11, 2015
    Posts:
    13
    Yeah it's part of the same System. I'll try the setComponentData function.
     
  4. RamonDevs

    RamonDevs

    Joined:
    Apr 11, 2015
    Posts:
    13
    Solved, see OP. I'm closing this ! (... can you close things in these forums...?)
     
    tomny likes this.